473,407 Members | 2,629 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,407 software developers and data experts.

how to get total cpu utilization and RAM memory utilization in percentage.

18
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.


Expand|Select|Wrap|Line Numbers
  1.     public PerformanceCounter cpuCounter;
  2.     public PerformanceCounter ramCounter;
  3.  
  4.       cpuCounter = new PerformanceCounter();
  5.         cpuCounter.CategoryName = "Processor";
  6.         cpuCounter.CounterName = "% Processor Time";
  7.         cpuCounter.InstanceName = "_Total";
  8.  
  9.         ramCounter = new PerformanceCounter("Memory", "Available MBytes");
  10.  
  11.         /* 
  12.         Call this method every time you need to know 
  13.         the current cpu usage. 
  14.         */
  15.     }
  16.     public string getCurrentCpuUsage()
  17.     {
  18.      return  cpuCounter.NextValue() + "%";
  19.     }
  20.  
  21.     /* 
  22.     Call this method every time you need to get 
  23.     the amount of the available RAM in Mb 
  24.     */
  25.     public string getAvailableRAM()
  26.     {
  27.         return ramCounter.NextValue() + "Mb";
  28.     }
Sep 12 '08 #1
7 13892
PRR
750 Expert 512MB
you can get lot of information using Windows Management Instrumentation or WMI...

here is a sample code ..

Expand|Select|Wrap|Line Numbers
  1. ManagementObjectSearcher searcher =new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Processor");
  2.  
  3.  
  4. foreach (ManagementObject queryObj in searcher.Get())
  5.                 {
  6. string s =Convert.ToString(queryObj["LoadPercentage"]).Trim();
  7. }
  8.  
  9.  
  10. ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");
  11.  
  12.                 foreach (ManagementObject queryObj in searcher.Get())
  13.                 {
  14.  
  15. Convert.ToString(queryObj["FreePhysicalMemory"]).Trim())
  16. Convert.ToString(queryObj["FreeVirtualMemory"]).Trim())
  17. Convert.ToString(queryObj["TotalVirtualMemorySize"]).Trim()));          
  18. Convert.ToString(queryObj["TotalVisibleMemorySize"]).Trim())
  19. }
  20.  
  21.  
Look up for Win32_operating system n other classes...
Processor load is in percentage.. ram you will have to calculate...

Performance counters is another way of doing this... though i think wmi queries from performance counters... (i may be wrong on this... )
Sep 12 '08 #2
balach
18
which namespace will be used in this case??
Sep 12 '08 #3
PRR
750 Expert 512MB
"which namespace will be used in this case??"
System.Management;
Sep 12 '08 #4
balach
18
thanks, for answer but i am unable to use "System.Management" in .aspx page
Sep 12 '08 #5
PRR
750 Expert 512MB
thanks, for answer but i am unable to use "System.Management" in .aspx page
did you add reference to System.Management?.... can you tell me wat exactly are you tryin? If you are tryin to get client info (client PC) by adding System.Management, code in .aspx... then the result that you get will be of the server PC... although you can remotely connect to client PC.. that require series of permission.. which are generally denied...still i think you can gather information ...by specifyin computer name in @"root\CIMV2\"
Sep 12 '08 #6
balach
18
thanks alot "dirtbag", i was missing to add reference in my project. this was little thing but i was much confused.

GOD BLESS U
Sep 12 '08 #7
Thanks. Big help for my project, also.
Oct 1 '10 #8

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

Similar topics

8
by: Tom Siltwater | last post by:
building variable width/DB tables etc using getrows instead of movenext. Performance is a major concern as this app requires SSL. My question is, when does it become more about the challenge of...
5
by: fwells11 | last post by:
Hi there. As you will see from my questions, I am an SQL newb. I dabble but never get to spend enough time to get proficient so base any feeedback on that basis please. This is all theoretical...
5
by: James Conrad StJohn Foreman | last post by:
Have found http://www-128.ibm.com/developerworks/db2/library/techarticle/lyle/0110lyle.html which is quite helpful, but doesn't quite tell me what I want. I have a table, advertising_spend with...
1
by: nazgul | last post by:
Hi all, I have an app that runs on multiple boxes. On my slackware box, running Python 2.5.1, top shows this: Mem: 1002736k total, 453268k used, 549468k free, 31392k buffers Swap: ...
0
by: Sam Samson | last post by:
Hi All, I wrote a little monitoring app in c# .. one of the things its supposed to do is report back how much memory the PC its on is using. my first pass at this was to iterate through the...
0
by: ipramod | last post by:
Hi, I just wanted to calculate CPU Percentage Utilization in ASP.Net application using a thread. I have written following code: protected void Page_Load(object sender, EventArgs e) {...
0
by: ipramod | last post by:
Hi, I just wanted to calculate CPU Percentage Utilization in ASP.Net application using a thread. I have written following code: protected void Page_Load(object sender, EventArgs e) {...
2
by: =?Utf-8?B?Um9oaXQ=?= | last post by:
..NET is a memory hog - plain and simple. This, in my opinion, makes it less than ideal for embedded applications where memory is constrained. I am forced to use .NET for reasons that I will not...
1
by: Kaheru | last post by:
memory utilization increase? This is because when i try to keep track of the CPU utilization and memory utilization of my FTP server process (ftpserver.exe), the CPU utilization increase, but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.