Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Required me to create a program that monitors the performance of the server By C # language .. Are there similar programs??
Posted
Comments
S@53K^S 13-Mar-12 16:20pm    
What parameters to monitor ??
saif khalid 13-Mar-12 16:43pm    
cpu,memory,hard
wizardzz 13-Mar-12 16:41pm    
I don't know about you're C# requirement, but PerfMon works.
saif khalid 13-Mar-12 16:48pm    
i don`t understand you
[no name] 13-Mar-12 21:51pm    
Repost

 
Share this answer
 
This is a big question. Let's do one step at a time.

Let's start with memory usage:

To monitor memory usage, you can use System.Diagnostics. Please see how to monitor memory per-process:
http://msdn.microsoft.com/en-us/library/s80a75e5%28v=vs.90%29.aspx[^].

(Sorry, the article is only for v.3.5 and below, but the methods themselves are not obsolete. Please check the MSDN help on each method referenced in this article to find the version for .NET Framework version you nee.)

You can summarize the memory usage by all processes you are interested in. You can get the an array of processes using the class System.Diagnostics.Process and one of its methods GetProcesses or GetProcessesByName, please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

—SA
 
Share this answer
 
v2
Now, let's see how to monitor hard drives.

You can use the class System.IO.DriveInfo, please see http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx[^].

C#
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
   if (drive.IsReady) {
       long freeSpace = drive.TotalFreeSpace;
       long size = drive.TotalSize;
       string name = drive.Name;
       //see the MSDN help page reference info for other drive properties
       //...
       ReportDriveInfo(freeSpace, size, name /* , ... */); //whatever you need for monotoring
   } else
      // do something to deal with non-ready drive; normally, it should not happen
}


Also, you can use push technology (http://en.wikipedia.org/wiki/Push_technology[^]) in monitoring drives. Instead of polling data periodically, which is always not very good, you can subscribe to some file system events and avoid polling data if nothing essential has changed. For this purpose, you can use the class System.IO.FileSystemWatcher; please see:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^].

You may find the idea of push technology very useful if you remember that file operations are relatively expensive, so you want to reduce number of polls.

—SA
 
Share this answer
 
v3
[Answering a follow-up question: how to monitor network traffic usage]

This is just one of the approaches: Microsoft provides a tool to monitor it, called Network Monitor:
http://en.wikipedia.org/wiki/Network_monitor[^],
http://blogs.technet.com/b/netmon/archive/2008/09/17/network-monitor-3-2-has-arrived.aspx[^],
http://www.microsoft.com/openspecifications/en/us/applied-interoperability/testing/network-monitor/default.aspx[^].

Download:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=4865[^].

It can be uses as is, but if you want to develop some monitoring code, it provides the API. Please see:
http://blogs.technet.com/b/netmon/archive/2008/10/29/intro-to-the-network-monitor-api.aspx[^].

I personally did not use it.

Another piece of software is offered by this CodeProject article:
IP Helper API - Retrieve TCP/IP/UDP Statistics, Interface details, ARP Table and Route Table[^].

Unfortunately, this is not written in .NET. You will need to use native DLL in your C# project. You have two options:



—SA
 
Share this answer
 
Comments
wizardzz 15-Mar-12 10:18am    
It concerns me that you have split your answer 3 ways. I think it makes the solutions section look a little sloppy, and I feel that I may not be alone in this.
Sergey Alexandrovich Kryukov 15-Mar-12 21:22pm    
I don't see why it concerns you. It's just was convenient to me. I have submit unrelated parts one by one. Even without such split I usually post way more detailed answers than average. How can it be a concern for anyone?

Sloppy? If you use adjective like that, it would be nice if you explained why exactly...

Thank you,
--SA
Form monitoring system memory, you can use the class System.Diagnostics.PerformanceCounter, please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter%28v=vs.100%29.aspx[^].

I think this simple code sample can give you clear idea on how to use it for CPU usage monitoring:
http://stackoverflow.com/questions/278071/how-to-get-the-cpu-usage-in-c[^].

—SA
 
Share this answer
 
Comments
saif khalid 14-Mar-12 7:29am    
Onset I would like to thank you for your cooperation with me ...

Now, after the monitor hard,memory and processor .. What can I also monitor in the server??? I need other ideas
Sergey Alexandrovich Kryukov 14-Mar-12 12:40pm    
You are welcome.
Well, would you accept my answers formally (green button) -- thank you.
Well, What else to monitor? Perhaps network traffic...
--SA
saif khalid 14-Mar-12 14:28pm    
I need any ideas that can i translate it in c# ..
Sergey Alexandrovich Kryukov 14-Mar-12 15:01pm    
It is in C#. Which part is not?
--SA
saif khalid 14-Mar-12 14:32pm    
if network traffic Benefit me and possible to apply the idea in c Sharp..help me
PerfMon Sample: Demonstrates How to Monitor System Performance Using Performance Counters[^] Is something that I would start to read and understand.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900