public TestResourcesAnalyzerMetricCacher(ICpuUsageCalculator cpuUsageCalculator) { if (PlatformDetails.RunningOnLinux) { _smapsReader = new SmapsReader(new[] { new byte[SmapsReader.BufferSize], new byte[SmapsReader.BufferSize] }); } Register(MetricCacher.Keys.Server.CpuUsage, TimeSpan.FromSeconds(1), cpuUsageCalculator.Calculate); Register(MetricCacher.Keys.Server.MemoryInfo, TimeSpan.FromSeconds(1), CalculateMemoryInfo); Register(MetricCacher.Keys.Server.MemoryInfoExtended, TimeSpan.FromSeconds(1), CalculateMemoryInfoExtended); }
public TestResourcesAnalyzerMetricCacher(ICpuUsageCalculator cpuUsageCalculator) { if (PlatformDetails.RunningOnLinux) { _smapsReader = new SmapsReader(new[] { new byte[SmapsReader.BufferSize], new byte[SmapsReader.BufferSize] }); } Register(Keys.Server.CpuUsage, _cacheRefreshRate, cpuUsageCalculator.Calculate); Register(Keys.Server.MemoryInfo, _cacheRefreshRate, CalculateMemoryInfo); Register(Keys.Server.MemoryInfoExtended, _cacheRefreshRate, CalculateMemoryInfoExtended); }
static TestResourcesAnalyzer() { _enabled = bool.TryParse(Environment.GetEnvironmentVariable("TEST_RESOURCE_ANALYZER_ENABLE"), out var value) && value; if (_enabled == false) { return; } _cpuUsageCalculator = CpuHelper.GetOSCpuUsageCalculator(); _metricCacher = new TestResourcesAnalyzerMetricCacher(_cpuUsageCalculator); _timer = new Timer(ProcessQueue, null, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15)); }
public TestResourceSnapshotWriter(string filename = null) { lock (_syncObject) { _cpuUsageCalculator = CpuHelper.GetOSCpuUsageCalculator(); _metricCacher = new TestResourcesAnalyzerMetricCacher(_cpuUsageCalculator); filename ??= $"TestResources_{DateTime.UtcNow:dd_MM_yyyy_HH_mm_ss}.csv"; var file = File.OpenWrite(filename); file.Position = 0; file.SetLength(0); _csvWriter = new CsvWriter(new StreamWriter(file), CultureInfo.InvariantCulture); _csvWriter.WriteHeader(typeof(TestResourceSnapshot)); } }
public static MachineResources GetMachineResources(SmapsReader smapsReader, ICpuUsageCalculator cpuUsageCalculator) { var memInfo = MemoryInformation.GetMemoryInfo(smapsReader, extendedInfo: true); var cpuInfo = cpuUsageCalculator.Calculate(); var machineResources = new MachineResources { TotalMemory = memInfo.TotalPhysicalMemory.GetValue(SizeUnit.Bytes), AvailableMemory = memInfo.AvailableMemory.GetValue(SizeUnit.Bytes), AvailableWithoutTotalCleanMemory = memInfo.AvailableWithoutTotalCleanMemory.GetValue(SizeUnit.Bytes), SystemCommitLimit = memInfo.TotalCommittableMemory.GetValue(SizeUnit.Bytes), CommittedMemory = memInfo.CurrentCommitCharge.GetValue(SizeUnit.Bytes), ProcessMemoryUsage = memInfo.WorkingSet.GetValue(SizeUnit.Bytes), IsWindows = PlatformDetails.RunningOnPosix == false, IsLowMemory = LowMemoryNotification.Instance.IsLowMemory(memInfo, smapsReader), LowMemoryThreshold = LowMemoryNotification.Instance.LowMemoryThreshold.GetValue(SizeUnit.Bytes), CommitChargeThreshold = LowMemoryNotification.Instance.GetCommitChargeThreshold(memInfo).GetValue(SizeUnit.Bytes), MachineCpuUsage = cpuInfo.MachineCpuUsage, ProcessCpuUsage = cpuInfo.ProcessCpuUsage }; return(machineResources); }
public MachineCpu(MetricCacher metricCacher, ICpuUsageCalculator calculator) : base(SnmpOids.Server.MachineCpu) { _metricCacher = metricCacher; _calculator = calculator; }
public MachineCpu(ICpuUsageCalculator calculator) : base(SnmpOids.Server.MachineCpu) { _calculator = calculator; }
public ProcessCpu(MetricCacher metricCacher, ICpuUsageCalculator calculator) : base(SnmpOids.Server.ProcessCpu) { _metricCacher = metricCacher; _calculator = calculator; }
public ProcessCpu(ICpuUsageCalculator calculator) : base(SnmpOids.Server.ProcessCpu) { _calculator = calculator; }
internal static MachineResources GetMachineResources(MetricCacher metricCacher, LowMemoryMonitor lowMemoryMonitor, ICpuUsageCalculator cpuUsageCalculator) { var memInfo = metricCacher.GetValue <MemoryInfoResult>(MetricCacher.Keys.Server.MemoryInfoExtended); var cpuInfo = metricCacher.GetValue(MetricCacher.Keys.Server.CpuUsage, cpuUsageCalculator.Calculate); var machineResources = new MachineResources { TotalMemory = memInfo.TotalPhysicalMemory.GetValue(SizeUnit.Bytes), AvailableMemory = memInfo.AvailableMemory.GetValue(SizeUnit.Bytes), AvailableWithoutTotalCleanMemory = memInfo.AvailableWithoutTotalCleanMemory.GetValue(SizeUnit.Bytes), SystemCommitLimit = memInfo.TotalCommittableMemory.GetValue(SizeUnit.Bytes), CommittedMemory = memInfo.CurrentCommitCharge.GetValue(SizeUnit.Bytes), ProcessMemoryUsage = memInfo.WorkingSet.GetValue(SizeUnit.Bytes), IsWindows = PlatformDetails.RunningOnPosix == false, IsLowMemory = LowMemoryNotification.Instance.IsLowMemory(memInfo, lowMemoryMonitor, out var commitChargeThreshold), LowMemoryThreshold = LowMemoryNotification.Instance.LowMemoryThreshold.GetValue(SizeUnit.Bytes), CommitChargeThreshold = commitChargeThreshold.GetValue(SizeUnit.Bytes), MachineCpuUsage = cpuInfo.MachineCpuUsage, ProcessCpuUsage = cpuInfo.ProcessCpuUsage }; return(machineResources); }