Ejemplo n.º 1
0
        private void GetNextValue(Stat stat, PerfCounterControl perfControl)
        {
            if (Util.EnvironmentTickCountSubtract(perfControl.lastFetch) > performanceCounterSampleInterval)
            {
                if (perfControl != null && perfControl.perfCounter != null)
                {
                    try
                    {
                        stat.Value = Math.Round(perfControl.perfCounter.NextValue(), 3);
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat("{0} Exception on NextValue fetching {1}: {2}", LogHeader, stat.Name, e);
                    }

                    perfControl.lastFetch = Util.EnvironmentTickCount();
                }
            }
        }
Ejemplo n.º 2
0
        public void RegisterServerStats()
        {
//            lastperformanceCounterSampleTime = Util.EnvironmentTickCount();
            PerformanceCounter tempPC;
            Stat tempStat;
            string tempName;

            try
            {
                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.
                tempStat = new Stat(tempName, tempName, "", "percent", CategoryServer, ContainerProcessor,
                                StatType.Pull, (s) => { GetNextValue(s, processorPercentPerfCounter); },
                                StatVerbosity.Info);
                StatsManager.RegisterStat(tempStat);
                RegisteredStats.Add(tempName, tempStat);

                MakeStat("TotalProcessorTime", null, "sec", ContainerProcessor,
                                    (s) => { s.Value = Math.Round(Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds, 3); });

                MakeStat("UserProcessorTime", null, "sec", ContainerProcessor,
                                    (s) => { s.Value = Math.Round(Process.GetCurrentProcess().UserProcessorTime.TotalSeconds, 3); });

                MakeStat("PrivilegedProcessorTime", null, "sec", ContainerProcessor,
                                    (s) => { s.Value = Math.Round(Process.GetCurrentProcess().PrivilegedProcessorTime.TotalSeconds, 3); });

                MakeStat("Threads", null, "threads", ContainerProcessor,
                                    (s) => { s.Value = Process.GetCurrentProcess().Threads.Count; });
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("{0} Exception creating 'Process': {1}", LogHeader, e);
            }

            MakeStat("BuiltinThreadpoolWorkerThreadsAvailable", null, "threads", ContainerThreadpool,
                s => 
                { 
                    int workerThreads, iocpThreads; 
                    ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); 
                    s.Value = workerThreads;
                });

            MakeStat("BuiltinThreadpoolIOCPThreadsAvailable", null, "threads", ContainerThreadpool,
                s => 
                { 
                    int workerThreads, iocpThreads; 
                    ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); 
                    s.Value = iocpThreads;
                });

            if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool && Util.GetSmartThreadPoolInfo() != null)
            {
                MakeStat("STPMaxThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MaxThreads);
                MakeStat("STPMinThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MinThreads);
                MakeStat("STPConcurrency", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MaxConcurrentWorkItems);
                MakeStat("STPActiveThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().ActiveThreads);
                MakeStat("STPInUseThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().InUseThreads);
                MakeStat("STPWorkItemsWaiting", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().WaitingCallbacks);
            }

            MakeStat(
                "HTTPRequestsMade", 
                "Number of outbound HTTP requests made", 
                "requests", 
                ContainerNetwork, 
                s => s.Value = WebUtil.RequestNumber,
                MeasuresOfInterest.AverageChangeOverTime);

            try
            {
                List<string> okInterfaceTypes = new List<string>(NetworkInterfaceTypes.Split(','));

                IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface nic in nics)
                {
                    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}'.",
                                                LogHeader, nic.Name, nicInterfaceType);
                        m_log.DebugFormat("{0}     To include, add to comma separated list in [Monitoring]NetworkInterfaceTypes={1}",
                                                LogHeader, NetworkInterfaceTypes);
                        continue;
                    }

                    if (nic.Supports(NetworkInterfaceComponent.IPv4))
                    {
                        IPv4InterfaceStatistics nicStats = nic.GetIPv4Statistics();
                        if (nicStats != null)
                        {
                            MakeStat("BytesRcvd/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                            (s) => { LookupNic(s, (ns) => { return ns.BytesReceived; }, 1024.0); });
                            MakeStat("BytesSent/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                            (s) => { LookupNic(s, (ns) => { return ns.BytesSent; }, 1024.0); });
                            MakeStat("TotalBytes/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                            (s) => { LookupNic(s, (ns) => { return ns.BytesSent + ns.BytesReceived; }, 1024.0); });
                        }
                    }
                    // TODO: add IPv6 (it may actually happen someday)
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("{0} Exception creating 'Network Interface': {1}", LogHeader, e);
            }

            MakeStat("ProcessMemory", null, "MB", ContainerMemory,
                                (s) => { s.Value = Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024d / 1024d, 3); });
            MakeStat("HeapMemory", null, "MB", ContainerMemory,
                                (s) => { s.Value = Math.Round(GC.GetTotalMemory(false) / 1024d / 1024d, 3); });
            MakeStat("LastHeapAllocationRate", null, "MB/sec", ContainerMemory,
                                (s) => { s.Value = Math.Round(MemoryWatchdog.LastHeapAllocationRate * 1000d / 1024d / 1024d, 3); });
            MakeStat("AverageHeapAllocationRate", null, "MB/sec", ContainerMemory,
                                (s) => { s.Value = Math.Round(MemoryWatchdog.AverageHeapAllocationRate * 1000d / 1024d / 1024d, 3); });
        }
Ejemplo n.º 3
0
 private void GetNextValue(Stat stat, PerfCounterControl perfControl, double factor)
 {
     if (Util.EnvironmentTickCountSubtract(perfControl.lastFetch) > performanceCounterSampleInterval)
     {
         if (perfControl != null && perfControl.perfCounter != null)
         {
             try
             {
                 // Kludge for factor to run double duty. If -1, subtract the value from one
                 if (factor == -1)
                     stat.Value = 1 - perfControl.perfCounter.NextValue();
                 else
                     stat.Value = perfControl.perfCounter.NextValue() / factor;
             }
             catch (Exception e)
             {
                 m_log.ErrorFormat("{0} Exception on NextValue fetching {1}: {2}", LogHeader, stat.Name, e);
             }
             perfControl.lastFetch = Util.EnvironmentTickCount();
         }
     }
 }
Ejemplo n.º 4
0
 private void GetNextValue(Stat stat, PerfCounterControl perfControl)
 {
     GetNextValue(stat, perfControl, 1.0);
 }
Ejemplo n.º 5
0
    public void RegisterServerStats()
    {
        lastperformanceCounterSampleTime = Util.EnvironmentTickCount();
        PerformanceCounter tempPC;
        Stat tempStat;
        string tempName;

        try
        {
            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.
            tempStat = new Stat(tempName, tempName, "", "percent", CategoryServer, ContainerProcessor,
                            StatType.Pull, (s) => { GetNextValue(s, processorPercentPerfCounter, Util.IsWindows() ? 1 : -1); },
                            StatVerbosity.Info);
            StatsManager.RegisterStat(tempStat);
            RegisteredStats.Add(tempName, tempStat);

            MakeStat("TotalProcessorTime", "sec", ContainerProcessor, 
                                (s) => { s.Value = Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds; });

            MakeStat("UserProcessorTime", "sec", ContainerProcessor,
                                (s) => { s.Value = Process.GetCurrentProcess().UserProcessorTime.TotalSeconds; });

            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)
        {
            m_log.ErrorFormat("{0} Exception creating 'Process': {1}", LogHeader, e);
        }

        try
        {
            List<string> okInterfaceTypes = new List<string>(NetworkInterfaceTypes.Split(','));

            IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface nic in nics)
            {
                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)
                    {
                        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); });
                    }
                }
            }
        }
        catch (Exception e)
        {
            m_log.ErrorFormat("{0} Exception creating 'Network Interface': {1}", LogHeader, e);
        }

        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); });
    }
Ejemplo n.º 6
0
        public void RegisterServerStats()
        {
//            lastperformanceCounterSampleTime = Util.EnvironmentTickCount();
            PerformanceCounter tempPC;
            Stat   tempStat;
            string tempName;

            try
            {
                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.
                tempStat = new Stat(tempName, tempName, "", "percent", CategoryServer, ContainerProcessor,
                                    StatType.Pull, (s) => { GetNextValue(s, processorPercentPerfCounter); },
                                    StatVerbosity.Info);
                StatsManager.RegisterStat(tempStat);
                RegisteredStats.Add(tempName, tempStat);

                MakeStat("TotalProcessorTime", null, "sec", ContainerProcessor,
                         (s) => { s.Value = Math.Round(Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds, 3); });

                MakeStat("UserProcessorTime", null, "sec", ContainerProcessor,
                         (s) => { s.Value = Math.Round(Process.GetCurrentProcess().UserProcessorTime.TotalSeconds, 3); });

                MakeStat("PrivilegedProcessorTime", null, "sec", ContainerProcessor,
                         (s) => { s.Value = Math.Round(Process.GetCurrentProcess().PrivilegedProcessorTime.TotalSeconds, 3); });

                MakeStat("Threads", null, "threads", ContainerProcessor,
                         (s) => { s.Value = Process.GetCurrentProcess().Threads.Count; });
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("{0} Exception creating 'Process': {1}", LogHeader, e);
            }

            MakeStat("BuiltinThreadpoolWorkerThreadsAvailable", null, "threads", ContainerThreadpool,
                     s =>
            {
                int workerThreads, iocpThreads;
                ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads);
                s.Value = workerThreads;
            });

            MakeStat("BuiltinThreadpoolIOCPThreadsAvailable", null, "threads", ContainerThreadpool,
                     s =>
            {
                int workerThreads, iocpThreads;
                ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads);
                s.Value = iocpThreads;
            });

            if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool && Util.GetSmartThreadPoolInfo() != null)
            {
                MakeStat("STPMaxThreads", null, "threads", ContainerThreadpool, s => s.Value       = Util.GetSmartThreadPoolInfo().MaxThreads);
                MakeStat("STPMinThreads", null, "threads", ContainerThreadpool, s => s.Value       = Util.GetSmartThreadPoolInfo().MinThreads);
                MakeStat("STPConcurrency", null, "threads", ContainerThreadpool, s => s.Value      = Util.GetSmartThreadPoolInfo().MaxConcurrentWorkItems);
                MakeStat("STPActiveThreads", null, "threads", ContainerThreadpool, s => s.Value    = Util.GetSmartThreadPoolInfo().ActiveThreads);
                MakeStat("STPInUseThreads", null, "threads", ContainerThreadpool, s => s.Value     = Util.GetSmartThreadPoolInfo().InUseThreads);
                MakeStat("STPWorkItemsWaiting", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().WaitingCallbacks);
            }

            MakeStat(
                "HTTPRequestsMade",
                "Number of outbound HTTP requests made",
                "requests",
                ContainerNetwork,
                s => s.Value = WebUtil.RequestNumber,
                MeasuresOfInterest.AverageChangeOverTime);

            try
            {
                List <string> okInterfaceTypes = new List <string>(NetworkInterfaceTypes.Split(','));

                IEnumerable <NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface nic in nics)
                {
                    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}'.",
                                          LogHeader, nic.Name, nicInterfaceType);
                        m_log.DebugFormat("{0}     To include, add to comma separated list in [Monitoring]NetworkInterfaceTypes={1}",
                                          LogHeader, NetworkInterfaceTypes);
                        continue;
                    }

                    if (nic.Supports(NetworkInterfaceComponent.IPv4))
                    {
                        IPv4InterfaceStatistics nicStats = nic.GetIPv4Statistics();
                        if (nicStats != null)
                        {
                            MakeStat("BytesRcvd/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                     (s) => { LookupNic(s, (ns) => { return(ns.BytesReceived); }, 1024.0); });
                            MakeStat("BytesSent/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                     (s) => { LookupNic(s, (ns) => { return(ns.BytesSent); }, 1024.0); });
                            MakeStat("TotalBytes/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                     (s) => { LookupNic(s, (ns) => { return(ns.BytesSent + ns.BytesReceived); }, 1024.0); });
                        }
                    }
                    // TODO: add IPv6 (it may actually happen someday)
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("{0} Exception creating 'Network Interface': {1}", LogHeader, e);
            }

            MakeStat("ProcessMemory", null, "MB", ContainerMemory,
                     (s) => { s.Value = Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024d / 1024d, 3); });
            MakeStat("HeapMemory", null, "MB", ContainerMemory,
                     (s) => { s.Value = Math.Round(GC.GetTotalMemory(false) / 1024d / 1024d, 3); });
            MakeStat("LastHeapAllocationRate", null, "MB/sec", ContainerMemory,
                     (s) => { s.Value = Math.Round(MemoryWatchdog.LastHeapAllocationRate * 1000d / 1024d / 1024d, 3); });
            MakeStat("AverageHeapAllocationRate", null, "MB/sec", ContainerMemory,
                     (s) => { s.Value = Math.Round(MemoryWatchdog.AverageHeapAllocationRate * 1000d / 1024d / 1024d, 3); });

            MakeStat("ProcessResident", null, "MB", ContainerProcess,
                     (s) =>
            {
                Process myprocess = Process.GetCurrentProcess();
                myprocess.Refresh();
                s.Value = Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024.0 / 1024.0);
            });
            MakeStat("ProcessPaged", null, "MB", ContainerProcess,
                     (s) =>
            {
                Process myprocess = Process.GetCurrentProcess();
                myprocess.Refresh();
                s.Value = Math.Round(Process.GetCurrentProcess().PagedMemorySize64 / 1024.0 / 1024.0);
            });
            MakeStat("ProcessVirtual", null, "MB", ContainerProcess,
                     (s) =>
            {
                Process myprocess = Process.GetCurrentProcess();
                myprocess.Refresh();
                s.Value = Math.Round(Process.GetCurrentProcess().VirtualMemorySize64 / 1024.0 / 1024.0);
            });
            MakeStat("PeakProcessResident", null, "MB", ContainerProcess,
                     (s) =>
            {
                Process myprocess = Process.GetCurrentProcess();
                myprocess.Refresh();
                s.Value = Math.Round(Process.GetCurrentProcess().PeakWorkingSet64 / 1024.0 / 1024.0);
            });
            MakeStat("PeakProcessPaged", null, "MB", ContainerProcess,
                     (s) =>
            {
                Process myprocess = Process.GetCurrentProcess();
                myprocess.Refresh();
                s.Value = Math.Round(Process.GetCurrentProcess().PeakPagedMemorySize64 / 1024.0 / 1024.0);
            });
            MakeStat("PeakProcessVirtual", null, "MB", ContainerProcess,
                     (s) =>
            {
                Process myprocess = Process.GetCurrentProcess();
                myprocess.Refresh();
                s.Value = Math.Round(Process.GetCurrentProcess().PeakVirtualMemorySize64 / 1024.0 / 1024.0);
            });
        }