mirror of
https://github.com/ryzij/ServerMonitor.git
synced 2026-07-14 03:46:58 +00:00
Добавил метод для получения нагрузки на процессор
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using MonitorAgent.Core.Abstraction;
|
||||
using MonitorAgent.Core.Models;
|
||||
|
||||
namespace MonitorAgent.Application.Services;
|
||||
|
||||
public class RawCpuMonitorService : ICpuMonitorService
|
||||
{
|
||||
public async Task<RawCpuStatsCollection> ParseRawCpuStatsAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var raw = await File.ReadAllLinesAsync("/proc/stat", cancellationToken);
|
||||
|
||||
var total = RawCpuStats.Parse(raw[0]);
|
||||
var cores = new List<RawCpuStats>();
|
||||
for (int i = 1; i < raw.Length && raw[i].StartsWith("cpu"); i++)
|
||||
cores.Add(RawCpuStats.Parse(raw[i]));
|
||||
|
||||
return new RawCpuStatsCollection(total, cores);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user