PerformanceCounter CPU 0% ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bobido
    New Member
    • Feb 2008
    • 13

    PerformanceCounter CPU 0% ???

    Hi there!

    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";
        }
    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!
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    I have the same results as you. I'm interested in this thread, hope someone has an answer.

    Comment

    Working...