Пример #1
0
        public void Collect(HostMetrics metrics)
        {
            var deltaSeconds = stopwatch.Elapsed.TotalSeconds;

            var newDisksStatsInfo = new Dictionary <string, DiskStats>();
            var disksUsageInfo    = new Dictionary <string, DiskUsageInfo>();

            foreach (var diskStats in ParseDiskstats(diskStatsReader.ReadLines()))
            {
                var result = new DiskUsageInfo {
                    DiskName = diskStats.DiskName
                };

                if (previousDisksStatsInfo.TryGetValue(diskStats.DiskName, out var previousDiskStats))
                {
                    FillInfo(result, previousDiskStats, diskStats, deltaSeconds);
                }

                disksUsageInfo[result.DiskName] = result;

                newDisksStatsInfo[diskStats.DiskName] = diskStats;
            }

            metrics.DisksUsageInfo = disksUsageInfo;

            previousDisksStatsInfo = newDisksStatsInfo;

            stopwatch.Restart();
        }
        public void Collect(HostMetrics metrics)
        {
            var deltaSeconds = stopwatch.Elapsed.TotalSeconds;

            var newNetworkUsageInfo        = new Dictionary <string, NetworkUsage>();
            var networkInterfacesUsageInfo = new Dictionary <string, NetworkInterfaceUsageInfo>();

            foreach (var networkUsage in ParseNetworkUsage())
            {
                var result = CreateInfo(networkUsage);

                if (previousNetworkUsageInfo.TryGetValue(networkUsage.InterfaceName, out var value))
                {
                    FillInfo(result, value, networkUsage, deltaSeconds);
                }

                newNetworkUsageInfo[networkUsage.InterfaceName] = networkUsage;

                networkInterfacesUsageInfo[networkUsage.InterfaceName] = result;
            }

            metrics.NetworkInterfacesUsageInfo = networkInterfacesUsageInfo;

            FillAggregatedNetworkInfo(metrics);

            previousNetworkUsageInfo = newNetworkUsageInfo;

            stopwatch.Restart();
        }
Пример #3
0
        public void Collect(HostMetrics metrics)
        {
            var diskSpaceInfos = new Dictionary <string, DiskSpaceInfo>();

            foreach (var info in GetDiskSpaceInfos())
            {
                if (!diskSpaceInfos.ContainsKey(info.DiskName))
                {
                    diskSpaceInfos[info.DiskName] = info;
                }
            }

            metrics.DisksSpaceInfo = diskSpaceInfos;
        }
Пример #4
0
        public void Collect(HostMetrics metrics)
        {
            var states = new Dictionary <TcpState, int>();

            foreach (var tcpConnection in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections())
            {
                if (!states.ContainsKey(tcpConnection.State))
                {
                    states[tcpConnection.State] = 0;
                }
                states[tcpConnection.State]++;
            }

            metrics.TcpStates = states;
        }
Пример #5
0
        private HostMetrics CollectInternal()
        {
            var metrics = new HostMetrics();

            CollectNativeMetrics(metrics);

            if (settings.CollectDiskSpaceMetrics)
            {
                diskSpaceCollector.Collect(metrics);
            }

            if (settings.CollectTcpStateMetrics)
            {
                tcpStateCollector.Collect(metrics);
            }

            return(metrics);
        }
Пример #6
0
        public void Collect(HostMetrics metrics)
        {
            var systemStat = settings.CollectCpuMetrics ? ReadSystemStat() : new SystemStat();
            var memInfo    = settings.CollectMemoryMetrics ? ReadMemoryInfo() : new MemoryInfo();
            var perfInfo   = settings.CollectMiscMetrics ? ReadPerformanceInfo() : new PerformanceInfo();

            if (systemStat.Filled)
            {
                var usedTime = systemStat.UserTime.Value + systemStat.NicedTime.Value +
                               systemStat.SystemTime.Value + systemStat.IdleTime.Value;

                cpuCollector.Collect(metrics, usedTime, systemStat.IdleTime.Value);
            }

            if (memInfo.Filled)
            {
                metrics.MemoryAvailable     = memInfo.AvailableMemory.Value;
                metrics.MemoryCached        = memInfo.CacheMemory.Value;
                metrics.MemoryKernel        = memInfo.KernelMemory.Value;
                metrics.MemoryTotal         = memInfo.TotalMemory.Value;
                metrics.MemoryFree          = memInfo.FreeMemory.Value;
                metrics.PageFaultsPerSecond = (long)hardPageFaultCollector.Collect(memInfo.MajorPageFaultCount.Value);
            }

            if (perfInfo.Filled)
            {
                metrics.HandleCount  = perfInfo.HandleCount.Value;
                metrics.ThreadCount  = perfInfo.ThreadCount.Value;
                metrics.ProcessCount = perfInfo.ProcessCount.Value;
            }

            if (settings.CollectNetworkUsageMetrics)
            {
                networkCollector.Collect(metrics);
            }

            if (settings.CollectDiskUsageMetrics)
            {
                diskUsageCollector.Collect(metrics);
            }
        }
Пример #7
0
        public void Collect(HostMetrics metrics, ulong systemTime, ulong idleTime)
        {
            var systemTimeDiff = (double)systemTime - previousSystemTime;
            var idleTimeDiff   = (double)idleTime - previousIdleTime;
            var spentTimeDiff  = 1 - idleTimeDiff / systemTimeDiff;

            metrics.CpuTotalCores = previousCoresCount = coresCountProvider() ?? previousCoresCount;

            if (previousSystemTime == 0 || systemTimeDiff <= 0)
            {
                metrics.CpuUtilizedCores    = 0d;
                metrics.CpuUtilizedFraction = 0d;
            }
            else
            {
                metrics.CpuUtilizedCores    = (metrics.CpuTotalCores * spentTimeDiff).Clamp(0, metrics.CpuTotalCores);
                metrics.CpuUtilizedFraction = spentTimeDiff.Clamp(0, 1);
            }

            previousSystemTime = systemTime;
            previousIdleTime   = idleTime;
        }
        private void FillAggregatedNetworkInfo(HostMetrics toFill)
        {
            var usedInterfaces = new HashSet <string>();

            foreach (var teamingInterface in toFill.NetworkInterfacesUsageInfo.Values.OfType <TeamingInterfaceUsageInfo>())
            {
                usedInterfaces.UnionWith(teamingInterface.ChildInterfaces);
                usedInterfaces.Add(teamingInterface.InterfaceName);

                toFill.NetworkSentBytesPerSecond      += teamingInterface.SentBytesPerSecond;
                toFill.NetworkReceivedBytesPerSecond  += teamingInterface.ReceivedBytesPerSecond;
                toFill.NetworkBandwidthBytesPerSecond += teamingInterface.BandwidthBytesPerSecond;
            }

            foreach (var basicInterface in toFill.NetworkInterfacesUsageInfo.Values
                     .Where(x => !usedInterfaces.Contains(x.InterfaceName)))
            {
                toFill.NetworkSentBytesPerSecond      += basicInterface.SentBytesPerSecond;
                toFill.NetworkReceivedBytesPerSecond  += basicInterface.ReceivedBytesPerSecond;
                toFill.NetworkBandwidthBytesPerSecond += basicInterface.BandwidthBytesPerSecond;
            }
        }
Пример #9
0
 private void CollectNativeMetrics(HostMetrics metrics)
 => nativeCollector?.Invoke(metrics);