現在、.NET COREを使用しているC#Webアプリケーションで現在のCPU/RAM /ディスク使用量を取得する方法を探しています。.NET COREを使用してC#Webアプリケーションで現在のCPU/RAM /ディスク使用量を取得する方法は?
CPUとRAMの使用については、System.DiagnosticsのPerformanceCounterクラスを使用します。 これらのコードです:ディスクの使用状況については
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";
}
、私がDriveInfoクラスを使用します。これらは、コードです:
using System;
using System.IO;
class Info {
public static void Main() {
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
//There are more attributes you can use.
//Check the MSDN link for a complete example.
Console.WriteLine(drive.Name);
if (drive.IsReady) Console.WriteLine(drive.TotalSize);
}
}
}
は、残念ながら、.NETのコアは、したがって、上記のコードが動作しない、DriveInfoとPerformanceCounterクラスをサポートしていません。
.NET COREを使用してC#Webアプリケーションで現在のCPU/RAM /ディスクの使用状況をどのように取得できるかを知っている人はいますか?
System.IO.FileSystem.DriveInfo
パッケージを追加することによって、コアのために利用可能です9376 – thepirat000P/Invokeは.NETコアですか?私はcoreclrで100%立ち上がったわけではありませんが、P/Invokeを持っていてネイティブのWindowsライブラリを呼び出すことができるなら、それを行う方法があります。 – Thumper