hi all,
i am new in .NET, some body please help me regarding calculating total cpu utilization and RAM memory utilization in percentage (Accurately) on page load event of ASP.NET.
i found the following code from web, but it is not running properly and also i have no idea what it will do, i heared that there will be used performance monitoring and donot know how to use it.
please help me with coding instructins.
- public PerformanceCounter cpuCounter;
-
public PerformanceCounter ramCounter;
-
-
cpuCounter = new PerformanceCounter();
-
cpuCounter.CategoryName = "Processor";
-
cpuCounter.CounterName = "% Processor Time";
-
cpuCounter.InstanceName = "_Total";
-
-
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
-
-
/*
-
Call this method every time you need to know
-
the current cpu usage.
-
*/
-
}
-
public string getCurrentCpuUsage()
-
{
-
return cpuCounter.NextValue() + "%";
-
}
-
-
/*
-
Call this method every time you need to get
-
the amount of the available RAM in Mb
-
*/
-
public string getAvailableRAM()
-
{
-
return ramCounter.NextValue() + "Mb";
-
}