473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PerformanceCounter CPU 0% ???

13
Hi there!

Currently I'm trying to display the current performance of my servers on my website. I tried it with the following code:

Expand|Select|Wrap|Line Numbers
  1.     protected static PerformanceCounter cpuCounter;
  2.     protected static PerformanceCounter ramCounter;
  3.  
  4.     protected void Page_Load(object sender, EventArgs e)
  5.     {
  6.         try
  7.         {
  8.             Timer1.Tick += new EventHandler<EventArgs>(Timer1_Tick);
  9.             Timer1.Interval = 2000;
  10.  
  11.             cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
  12.             ramCounter = new PerformanceCounter("Memory", "Available MBytes");
  13.         }
  14.         catch (Exception exc)
  15.         { 
  16.         lbl_error.Text = "Error: " + exc.Message;
  17.         }
  18.     }
  19.  
  20.     void Timer1_Tick(object sender, EventArgs e)
  21.     {
  22.         lbl_text.Text = "<b>WebServer</b> <br/>";
  23.         lbl_text.Text += "CPU Usage: " +getCurrentCpuUsage() + "<br/>";
  24.         lbl_text.Text += "Available Ram: " + getAvailableRAM() + "<br/>";
  25.     }
  26.  
  27.     public string getCurrentCpuUsage()
  28.     {
  29.         return cpuCounter.NextValue() + "%";
  30.     }
  31.     public string getAvailableRAM()
  32.     {
  33.             return ramCounter.NextValue()+"Mb";
  34.     }
  35.  
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!
Jan 27 '09 #1
1 4176
Curtis Rutland
3,256 Expert 2GB
I have the same results as you. I'm interested in this thread, hope someone has an answer.
Jan 27 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: W1ld0ne74 | last post by:
I am implimenting Performance counters into a web application. I use the following code to create the counters during setup: private void SetupPerfCntrs() {...
1
by: Chris | last post by:
I'm trying to do something really easy: just get the % CPU load. However, I just get mostly 0's sprinkled with an occasional 100. I poked around on the web for info, but all the stuff I found (I...
1
by: jimbo | last post by:
Here is my problem. I'm creating an Instrumentation class that will use previously created Performance Categories and Counters in order to time various processes (ie. query duration etc.). This...
0
by: BuddyWork | last post by:
Hello, Can someone please explain why my Instances are not appearing in Perfmon. Here is my code to create the counters. CounterCreationDataCollection CCDC = new...
0
by: Michiel | last post by:
Hello, I'm trying to retrieve my cpu load as follows : PerformanceCounter* cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); float value =...
0
by: Henning Krause [MVP] | last post by:
Hello, I've created a simple website which instantiates a PerformanceCounter object on any existing counter. On the Page_Load() event I set a label to the value of the performancecounter (via...
3
by: Rob Meade | last post by:
Hi all, I'm having a bit of trouble with the following function.... Private Function GetSystemUpTime() As TimeSpan ' declare variables Dim Result As TimeSpan Dim PerformanceCounter As...
0
by: Scheu | last post by:
Hi all, I'm hoping someone can help me with this bizarre problem. If I create a new PerformanceCounter object in a ComVisible class and invoke it from wscript, it never seems to terminate. When...
3
by: Geoff McElhanon | last post by:
I have been struggling with a security issue that occurs under .NET 2.0, but does not occur under .NET 1.1. Essentially I am trying to open up a performance counter on a remote server and monitor...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.