Hi there!
Currently I'm trying to display the current performance of my servers on my website. I tried it with the following code:
Currently only the available ram is being showed on the page and the CPU load stays on 0% while in the Performance monitor of Microsoft it says otherwise :S
Thanks in advanced!
Currently I'm trying to display the current performance of my servers on my website. I tried it with the following code:
Code:
protected static PerformanceCounter cpuCounter;
protected static PerformanceCounter ramCounter;
protected void Page_Load(object sender, EventArgs e)
{
try
{
Timer1.Tick += new EventHandler<EventArgs>(Timer1_Tick);
Timer1.Interval = 2000;
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
}
catch (Exception exc)
{
lbl_error.Text = "Error: " + exc.Message;
}
}
void Timer1_Tick(object sender, EventArgs e)
{
lbl_text.Text = "<b>WebServer</b> <br/>";
lbl_text.Text += "CPU Usage: " +getCurrentCpuUsage() + "<br/>";
lbl_text.Text += "Available Ram: " + getAvailableRAM() + "<br/>";
}
public string getCurrentCpuUsage()
{
return cpuCounter.NextValue() + "%";
}
public string getAvailableRAM()
{
return ramCounter.NextValue()+"Mb";
}
Thanks in advanced!
Comment