mirror of
https://github.com/ryzij/ServerMonitor.git
synced 2026-07-14 03:46:58 +00:00
19 lines
662 B
C#
19 lines
662 B
C#
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);
|
|
}
|
|
} |