How to get the current CPU/RAM/Disk usage in a C# web application using .NET CORE?

前端 未结 3 549
抹茶落季
抹茶落季 2020-12-16 14:46

I am currently looking for a way to get the current CPU/RAM/Disk usage in a C# web application using .NET CORE.

For CPU and ram usage, I use PerformanceCounter Class

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 14:56

    Processor information is available via System.Diagnostics:

    var proc = Process.GetCurrentProcess();
    var mem = proc.WorkingSet64;
    var cpu = proc.TotalProcessorTime;
    Console.WriteLine("My process used working set {0:n3} K of working set and CPU {1:n} msec", 
        mem / 1024.0, cpu.TotalMilliseconds);
    

    DriveInfo is available for Core by adding the System.IO.FileSystem.DriveInfo package

提交回复
热议问题