diff --git a/OpenSim/Region/OptionalModules/Framework/Monitoring/ServerStats.cs b/OpenSim/Region/OptionalModules/Framework/Monitoring/ServerStats.cs index 8f60c8d7d6..a3d24363b1 100644 --- a/OpenSim/Region/OptionalModules/Framework/Monitoring/ServerStats.cs +++ b/OpenSim/Region/OptionalModules/Framework/Monitoring/ServerStats.cs @@ -63,6 +63,7 @@ public class ServerStats : ISharedRegionModule public readonly string ContainerNetwork = "network"; public readonly string ContainerProcess = "process"; + public string NetworkInterfaceTypes = "Ethernet"; readonly int performanceCounterSampleInterval = 500; int lastperformanceCounterSampleTime = 0; @@ -86,20 +87,6 @@ public class ServerStats : ISharedRegionModule PerfCounterControl processorPercentPerfCounter = null; - PerfCounterControl processThreadCountPerfCounter = null; - PerfCounterControl processVirtualBytesPerfCounter = null; - PerfCounterControl processWorkingSetPerfCounter = null; - - PerfCounterControl dotNETCLRMemoryAllocatedBytesPerSecPerfCounter = null; - PerfCounterControl dotNETCLRMemoryGen0HeapSizePerfCounter = null; - PerfCounterControl dotNETCLRMemoryGen1HeapSizePerfCounter = null; - PerfCounterControl dotNETCLRMemoryGen2HeapSizePerfCounter = null; - - PerfCounterControl dotNETCLRLaTTotalContentionsPerfCounter = null; - PerfCounterControl dotNETCLRLaTContentionsPerSecPerfCounter = null; - PerfCounterControl dotNETCLRLaTLogicalThreadsPerfCounter = null; - PerfCounterControl dotNETCLRLaTPhysicalThreadsPerfCounter = null; - #region ISharedRegionModule // IRegionModuleBase.Name public string Name { get { return "Server Stats"; } } @@ -108,10 +95,15 @@ public class ServerStats : ISharedRegionModule // IRegionModuleBase.Initialize public void Initialise(IConfigSource source) { - IConfig cnfg = source.Configs["Statistics"]; + IConfig cfg = source.Configs["Monitoring"]; - if (cnfg != null) - Enabled = cnfg.GetBoolean("Enabled", true); + if (cfg != null) + Enabled = cfg.GetBoolean("ServerStatsEnabled", true); + + if (Enabled) + { + NetworkInterfaceTypes = cfg.GetString("NetworkInterfaceTypes", "Ethernet"); + } } // IRegionModuleBase.Close public void Close() @@ -148,6 +140,13 @@ public class ServerStats : ISharedRegionModule } #endregion ISharedRegionModule + private void MakeStat(string pName, string pUnit, string pContainer, Action act) + { + Stat stat = new Stat(pName, pName, "", pUnit, CategoryServer, pContainer, StatType.Pull, act, StatVerbosity.Info); + StatsManager.RegisterStat(stat); + RegisteredStats.Add(pName, stat); + } + public void RegisterServerStats() { lastperformanceCounterSampleTime = Util.EnvironmentTickCount(); @@ -157,7 +156,7 @@ public class ServerStats : ISharedRegionModule try { - tempName = "CPU_Percent"; + tempName = "CPUPercent"; tempPC = new PerformanceCounter("Processor", "% Processor Time", "_Total"); processorPercentPerfCounter = new PerfCounterControl(tempPC); // A long time bug in mono is that CPU percent is reported as CPU percent idle. Windows reports CPU percent busy. @@ -167,31 +166,17 @@ public class ServerStats : ISharedRegionModule StatsManager.RegisterStat(tempStat); RegisteredStats.Add(tempName, tempStat); - /* Performance counters are not the way to go. Ick. Find another way. - tempName = "Thread_Count"; - tempPC = new PerformanceCounter("Process", "Thread Count", AppDomain.CurrentDomain.FriendlyName); - processThreadCountPerfCounter = new PerfCounterControl(tempPC); - tempStat = new Stat("Thread_Count", "Thread_Count", "", "threads", CategoryServer, ContainerProcess, - StatType.Pull, (s) => { GetNextValue(s, processThreadCountPerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); + MakeStat("TotalProcessorTime", "sec", ContainerProcessor, + (s) => { s.Value = Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds; }); - tempName = "Virtual_Bytes"; - tempPC = new PerformanceCounter("Process", "Virtual Bytes", AppDomain.CurrentDomain.FriendlyName); - processVirtualBytesPerfCounter = new PerfCounterControl(tempPC); - tempStat = new Stat("Virtual_Bytes", "Virtual_Bytes", "", "MB", CategoryServer, ContainerProcess, - StatType.Pull, (s) => { GetNextValue(s, processVirtualBytesPerfCounter, 1024.0*1024.0); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); + MakeStat("UserProcessorTime", "sec", ContainerProcessor, + (s) => { s.Value = Process.GetCurrentProcess().UserProcessorTime.TotalSeconds; }); - tempName = "Working_Set"; - tempPC = new PerformanceCounter("Process", "Working Set", AppDomain.CurrentDomain.FriendlyName); - processWorkingSetPerfCounter = new PerfCounterControl(tempPC); - tempStat = new Stat("Working_Set", "Working_Set", "", "MB", CategoryServer, ContainerProcess, - StatType.Pull, (s) => { GetNextValue(s, processWorkingSetPerfCounter, 1024.0*1024.0); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - */ + MakeStat("PrivilegedProcessorTime", "sec", ContainerProcessor, + (s) => { s.Value = Process.GetCurrentProcess().PrivilegedProcessorTime.TotalSeconds; }); + + MakeStat("Threads", "threads", ContainerProcessor, + (s) => { s.Value = Process.GetCurrentProcess().Threads.Count; }); } catch (Exception e) { @@ -200,112 +185,33 @@ public class ServerStats : ISharedRegionModule try { - /* The ".NET CLR *" categories aren't working for me. - tempName = ""Bytes_Allocated_Per_Sec"; - tempPC = new PerformanceCounter(".NET CLR Memory", "Allocated Bytes/sec", AppDomain.CurrentDomain.FriendlyName); - dotNETCLRMemoryAllocatedBytesPerSecPerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat(tempName, tempName, "", "bytes/sec", ServerCategory, MemoryContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRMemoryAllocatedBytesPerSecPerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); + List okInterfaceTypes = new List(NetworkInterfaceTypes.Split(',')); - tempName = "Gen_0_Heap_Size"; - tempPC = new PerformanceCounter(".NET CLR Memory", "Gen 0 heap size", AppDomain.CurrentDomain.FriendlyName); - dotNETCLRMemoryGen0HeapSizePerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat("Gen_0_Heap_Size", "Gen_0_Heap_Size", "", "bytes", ServerCategory, MemoryContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRMemoryGen0HeapSizePerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Gen_1_Heap_Size"; - tempPC = new PerformanceCounter(".NET CLR Memory", "Gen 1 heap size", AppDomain.CurrentDomain.FriendlyName); - dotNETCLRMemoryGen1HeapSizePerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat("Gen_1_Heap_Size", "Gen_1_Heap_Size", "", "bytes", ServerCategory, MemoryContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRMemoryGen1HeapSizePerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Gen_2_Heap_Size"; - tempPC = new PerformanceCounter(".NET CLR Memory", "Gen 2 heap size", AppDomain.CurrentDomain.FriendlyName); - dotNETCLRMemoryGen2HeapSizePerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat("Gen_2_Heap_Size", "Gen_2_Heap_Size", "", "bytes", ServerCategory, MemoryContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRMemoryGen2HeapSizePerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Total_Lock_Contentions"; - tempPC = new PerformanceCounter(".NET CLR LocksAndThreads", "Total # of Contentions"); - dotNETCLRLaTTotalContentionsPerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat("Total_Lock_Contentions", "Total_Lock_Contentions", "", "contentions", ServerCategory, ProcessContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRLaTTotalContentionsPerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Lock_Contentions"; - tempPC = new PerformanceCounter(".NET CLR LocksAndThreads", "Contention Rate / sec"); - dotNETCLRLaTContentionsPerSecPerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat("Lock_Contentions", "Lock_Contentions", "", "contentions/sec", ServerCategory, ProcessContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRLaTContentionsPerSecPerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Logical_Threads"; - tempPC = new PerformanceCounter(".NET CLR LocksAndThreads", "# of current logical Threads"); - dotNETCLRLaTLogicalThreadsPerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat("Logicial_Threads", "Logicial_Threads", "", "threads", ServerCategory, ProcessContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRLaTLogicalThreadsPerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Physical_Threads"; - tempPC = new PerformanceCounter(".NET CLR LocksAndThreads", "# of current physical Threads"); - dotNETCLRLaTPhysicalThreadsPerfCounter = new PerfCounterControl(tempPC, tempStat); - tempStat = new Stat("Physical_Threads", "Physical_Threads", "", "threads", ServerCategory, ProcessContainer, - StatType.Pull, (s) => { GetNextValue(s, dotNETCLRLaTPhysicalThreadsPerfCounter); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - */ - } - catch (Exception e) - { - m_log.ErrorFormat("{0} Exception creating '.NET CLR Memory': {1}", LogHeader, e); - } - - try - { IEnumerable nics = NetworkInterface.GetAllNetworkInterfaces(); - // IEnumerable nics = NetworkInterface.GetAllNetworkInterfaces().Where( - // (network) => network.NetworkInterfaceType == NetworkInterfaceType.Ethernet); - // IEnumerable nics = NetworkInterface.GetAllNetworkInterfaces().Where( - // (network) => network.OperationalStatus == OperationalStatus.Up); - foreach (NetworkInterface nic in nics) { - if (nic.OperationalStatus != OperationalStatus.Up || nic.NetworkInterfaceType != NetworkInterfaceType.Ethernet) + if (nic.OperationalStatus != OperationalStatus.Up) continue; + string nicInterfaceType = nic.NetworkInterfaceType.ToString(); + if (!okInterfaceTypes.Contains(nicInterfaceType)) + { + m_log.DebugFormat("{0} Not including stats for network interface '{1}' of type '{2}'. To include, add to [Monitoring]NetworkInterfaceTypes='Ethernet,Loopback'", + LogHeader, nic.Name, nicInterfaceType); + continue; + } + if (nic.Supports(NetworkInterfaceComponent.IPv4)) { IPv4InterfaceStatistics nicStats = nic.GetIPv4Statistics(); if (nicStats != null) { - tempName = "Bytes_Rcvd/" + nic.Name; - tempStat = new Stat(tempName, tempName, nic.Name, "KB", CategoryServer, ContainerNetwork, - StatType.Pull, (s) => { LookupNic(s, (ns) => { return ns.BytesReceived; }, 1024.0); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Bytes_Sent/" + nic.Name; - tempStat = new Stat(tempName, tempName, nic.Name, "KB", CategoryServer, ContainerNetwork, - StatType.Pull, (s) => { LookupNic(s, (ns) => { return ns.BytesSent; }, 1024.0); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Total_Bytes/" + nic.Name; - tempStat = new Stat(tempName, tempName, nic.Name, "KB", CategoryServer, ContainerNetwork, - StatType.Pull, (s) => { LookupNic(s, (ns) => { return ns.BytesSent + ns.BytesReceived; }, 1024.0); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); + MakeStat("BytesRcvd/" + nic.Name, "KB", ContainerNetwork, + (s) => { LookupNic(s, (ns) => { return ns.BytesReceived; }, 1024.0); }); + MakeStat("BytesSent/" + nic.Name, "KB", ContainerNetwork, + (s) => { LookupNic(s, (ns) => { return ns.BytesSent; }, 1024.0); }); + MakeStat("TotalBytes/" + nic.Name, "KB", ContainerNetwork, + (s) => { LookupNic(s, (ns) => { return ns.BytesSent + ns.BytesReceived; }, 1024.0); }); } } } @@ -315,30 +221,14 @@ public class ServerStats : ISharedRegionModule m_log.ErrorFormat("{0} Exception creating 'Network Interface': {1}", LogHeader, e); } - tempName = "Process_Memory"; - tempStat = new Stat(tempName, tempName, "", "MB", CategoryServer, ContainerMemory, - StatType.Pull, (s) => { s.Value = Process.GetCurrentProcess().WorkingSet64 / 1024d / 1024d; }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Object_Memory"; - tempStat = new Stat(tempName, tempName, "", "MB", CategoryServer, ContainerMemory, - StatType.Pull, (s) => { s.Value = GC.GetTotalMemory(false) / 1024d / 1024d; }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Last_Memory_Churn"; - tempStat = new Stat(tempName, tempName, "", "MB/sec", CategoryServer, ContainerMemory, - StatType.Pull, (s) => { s.Value = Math.Round(MemoryWatchdog.LastMemoryChurn * 1000d / 1024d / 1024d, 3); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - - tempName = "Average_Memory_Churn"; - tempStat = new Stat(tempName, tempName, "", "MB/sec", CategoryServer, ContainerMemory, - StatType.Pull, (s) => { s.Value = Math.Round(MemoryWatchdog.AverageMemoryChurn * 1000d / 1024d / 1024d, 3); }, StatVerbosity.Info); - StatsManager.RegisterStat(tempStat); - RegisteredStats.Add(tempName, tempStat); - + MakeStat("ProcessMemory", "MB", ContainerMemory, + (s) => { s.Value = Process.GetCurrentProcess().WorkingSet64 / 1024d / 1024d; }); + MakeStat("ObjectMemory", "MB", ContainerMemory, + (s) => { s.Value = GC.GetTotalMemory(false) / 1024d / 1024d; }); + MakeStat("LastMemoryChurn", "MB/sec", ContainerMemory, + (s) => { s.Value = Math.Round(MemoryWatchdog.LastMemoryChurn * 1000d / 1024d / 1024d, 3); }); + MakeStat("AverageMemoryChurn", "MB/sec", ContainerMemory, + (s) => { s.Value = Math.Round(MemoryWatchdog.AverageMemoryChurn * 1000d / 1024d / 1024d, 3); }); } // Notes on performance counters: