I'm currently looking for a way to get current CPU / RAM / Disk usage in a C # web application using .NET CORE.
To use the CPU and ram, I use the PerformanceCounter Class from System.Diagnostics. These are the codes:
PerformanceCounter cpuCounter; PerformanceCounter ramCounter; cpuCounter = new PerformanceCounter(); cpuCounter.CategoryName = "Processor"; cpuCounter.CounterName = "% Processor Time"; cpuCounter.InstanceName = "_Total"; ramCounter = new PerformanceCounter("Memory", "Available MBytes"); public string getCurrentCpuUsage(){ cpuCounter.NextValue()+"%"; } public string getAvailableRAM(){ ramCounter.NextValue()+"MB"; }
To use the disk, I use the DriveInfo class. These are the codes:
using System; using System.IO; class Info { public static void Main() { DriveInfo[] drives = DriveInfo.GetDrives(); foreach (DriveInfo drive in drives) {
Unfortunately, .NET Core does not support the DriveInfo and PerformanceCounter classes, so the codes above do not work.
Does anyone know how I can get the current CPU / RAM / Disk usage in a C # web application using .NET CORE?
source share