Solved

C# code to monitor CPU

Posted on 2004-03-22
5
2,655 Views
Last Modified: 2007-12-19
i have to develop a C# code to monitor CPU and memory usage of any host in the Internet.Assume there is no security restriction
0
Comment
Question by:Hermoinee
5 Comments
 
LVL 1

Expert Comment

by:lorddef
ID: 10649780
I'm sure there is. Unless its a machine you have access to...
0
 
LVL 4

Expert Comment

by:kolpdc
ID: 10650314
i am absolutely sure that you do not have access from your computer to clients spread throughout the network. it should not be allowed. else you could collect all data of all cumputers connected to the internet.

if you are able to put little "satellite"-apps onto each client you want to monitor (for example in intranet), then there should be a possibility.
1.1) every satellite detects the data and writes it into a database (db, file, ...)
1.2.) ... sends collected data to a server containing more intelligence

2.) activeX-control and webbrowser? (microsoft-TECHNICs...;)
0
 
LVL 22

Accepted Solution

by:
cookre earned 500 total points
ID: 10652924
Both of those requests can be handled by the c# WMI interface.

For available on the local box:
mgmtScope = new ManagementScope("root\\cimv2");
mgmtScope.Connect();
System.Management.ObjectQuery oqr = new System.Management.ObjectQuery("SELECT * FROM Win32_PerfRawData_PerfOS_Memory");
ManagementObjectSearcher query1r = new ManagementObjectSearcher(mgmtScope,oqr);
ManagementObjectCollection queryCollection1r = query1r.Get();            
foreach(ManagementObject mo in queryCollection1r)
       {
       return (UInt64)mo["AvailableBytes"];
       }  

Here's a description of what ManagementScope() looks like for remote boxes:
http://www.csharphelp.com/archives2/archive334.html

For CPU usage, you'll have to sift through these to decide which you want:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfformatteddata_perfos_processor.asp
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 84
stringclean challenge 26 56
recursion example 16 69
Modify a small python script 19 53
Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now