相关疑难解决方法(0)

.NET Core性能计数器的故事是什么?

在Windows下,可以使用以下方法读取.NET性能计数器:

  • 性能监视器
  • C#使用 PerformanceCounter
  • WMI并查询.NET相关的类

考虑到最近发布的.NET Core以及此类应用程序也可以在Linux中运行的事实,如何访问Windows上当前可用的.NET相关统计数据?

.net c# linux windows .net-core

23
推荐指数
2
解决办法
6586
查看次数

如何使用.NET CORE获取C#Web应用程序中的当前CPU / RAM /磁盘使用情况?

我目前正在寻找一种使用.NET CORE在C#Web应用程序中获取当前CPU / RAM /磁盘使用情况的方法。

对于CPU和内存的使用,我使用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";
}
Run Code Online (Sandbox Code Playgroud)

对于磁盘使用,我使用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); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

7
推荐指数
2
解决办法
3856
查看次数

标签 统计

c# ×2

.net ×1

.net-core ×1

asp.net-core ×1

linux ×1

windows ×1