Click here to Skip to main content
15,441,078 members
Articles / Programming Languages / C#
Posted 4 Nov 2003


98 bookmarked

Performance Monitor Grid

Rate me:
Please Sign up or sign in to vote.
4.47/5 (19 votes)
4 Nov 20031 min read
Tool to monitor machines on network.



The Performance Monitor Grid (PMG) displays performance counters of machines on a network in a DataGrid format. Each row in the DataGrid indicates the CPU%, Available Memory (in Megabytes) and Disk % for a particular host. A user can monitor up to 5 machines on the network at a time.

When closed, the application window remains in the systray and would "alert" the user if the performance counters on any host exceeds a certain threshold.


Well, cutting to the chase, I am currently learning C# and writing some code along the way sounded good to me. If any piece of code in this app becomes useful to you any day, I would be really happy!

Using the code

The code uses .NET's WMI PerfRawData classes of the System.Management namespace. Figuring out how to make sense out of the "raw data" returned by these classes was a pain and I had to spend quite sometime in MSDN and Google for that!

The PerfRow class is the core class of the application. A separate instance of this class is created for each row in the DataGrid. The code below shows the connect method of the PerfRow class to connect to a host.

public int Connect()
    if (Dns.GetHostName() == strHostName)
        mgmtScope = new 
          ManagementScope("\\\\" + strHostName+ "\\root\\cimv2");
        options          = new ConnectionOptions();
        options.Username = strUserName;
        options.Password = strPassword;

        // scope object for remote machine
        mgmtScope = new 
          ManagementScope("\\\\" + strHostName + "\\root\\cimv2",options);

    // connect to machine to monitor. Return 0 if not able to connect
        return 0;

    // CPU%
    mPath_CPU                = new ManagementPath();
    mPath_CPU.RelativePath   = "Win32_PerfRawData_PerfOS_Processor.Name='0'";
    mObject_CPU  = new ManagementObject(mgmtScope,mPath_CPU,null);

    // Memory Available (in MBytes)
    mPath_Mem                = new ManagementPath();
    mPath_Mem.RelativePath   = "Win32_PerfRawData_PerfOS_Memory";
    mc  = new ManagementClass(mgmtScope,mPath_Mem,null);

    // Disk %            
    mPath_Disk               = new ManagementPath();
    mPath_Disk.RelativePath  = 
    mObject_Disk = new ManagementObject(mgmtScope,mPath_Disk,null);

    return 1;

The PerfRow class contains the GetCPU(), GetDisk() and the GetMemory() methods to return the respective performance counters.

public string GetCPU()
    decimal PercentProcessorTime=0;

    ulong  u_newCPU   = 
    ulong u_newNano   = 
    decimal d_newCPU  = Convert.ToDecimal(u_newCPU);
    decimal d_newNano = Convert.ToDecimal(u_newNano);
    decimal d_oldCPU  = Convert.ToDecimal(u_oldCPU);
    decimal d_oldNano = Convert.ToDecimal(u_oldNano);

    // Thanks to MSDN for giving me this formula !
    PercentProcessorTime = 
      (1 - ((d_newCPU-d_oldCPU)/(d_newNano - d_oldNano)))*100m;

    // Save the values for the next run
    u_oldCPU          = u_newCPU;
    u_oldNano         = u_newNano;
    return PercentProcessorTime.ToString("N",nfi);;

Points of interest

Need to add a lot of tweaks to the code. I have just about ignored cleaning up memory. Also would like to introduce an e-mailing feature in the alerts.


First cut on November 4th 2003


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

Questionplz help Pin
karan rana16-Nov-11 4:55
Memberkaran rana16-Nov-11 4:55 
QuestionAny one know how to pass this data to a database ? Pin
partialdata12-Jan-09 9:56
Memberpartialdata12-Jan-09 9:56 
Questioncan we get it for windows mobile 6.0 Pin
Member 29629135-Aug-08 9:34
MemberMember 29629135-Aug-08 9:34 
AnswerRe: can we get it for windows mobile 6.0 Pin
partialdata12-Jan-09 9:55
Memberpartialdata12-Jan-09 9:55 
QuestionProblem with Vista Pin
asp_guy30-Nov-07 4:54
Memberasp_guy30-Nov-07 4:54 
GeneralRe: Problem with Vista Pin
kameshpareek22-Apr-08 20:34
Memberkameshpareek22-Apr-08 20:34 
QuestionProblem with Vista Pin
asp_guy30-Nov-07 4:53
Memberasp_guy30-Nov-07 4:53 
GeneralPerformance grid for each process Pin
christalin27-Jul-07 3:58
Memberchristalin27-Jul-07 3:58 
GeneralRe: Performance grid for each process Pin
Member 473692627-Feb-09 4:14
MemberMember 473692627-Feb-09 4:14 
GeneralGood Job Pin
vincent73723-Jul-07 21:05
Membervincent73723-Jul-07 21:05 
GeneralGood work buddy Pin
\laddie12-Dec-06 17:22
Member\laddie12-Dec-06 17:22 
GeneralGetting the CPU% Dynamically Pin
SidathRatnajeewa6-Jul-06 23:03
MemberSidathRatnajeewa6-Jul-06 23:03 
Questionplz help me in adding 2 more columns Pin
cabinet36912-Feb-06 0:14
Membercabinet36912-Feb-06 0:14 
GeneralGr8 ! job but i ve a doubt Pin
cabinet36911-Jan-06 1:54
Membercabinet36911-Jan-06 1:54 
QuestionWhat CPU% means? Pin
Win32nipuh11-Feb-05 0:56
professionalWin32nipuh11-Feb-05 0:56 
Generalit doesn't work in xp Pin
kimshw6-May-04 20:02
Memberkimshw6-May-04 20:02 
GeneralRe: it doesn't work in xp Pin
Ineffable22-Sep-04 11:49
MemberIneffable22-Sep-04 11:49 
Generalrstatd Pin
retZ14-Apr-04 7:02
MemberretZ14-Apr-04 7:02 
Questioncan we get the usage of Win98? Pin
arahmad8231-Mar-04 9:39
Memberarahmad8231-Mar-04 9:39 
AnswerRe: can we get the usage of Win98? Pin
Ineffable22-Sep-04 11:50
MemberIneffable22-Sep-04 11:50 
GeneralFormulas Pin
ratoncete30-Jan-04 3:10
Memberratoncete30-Jan-04 3:10 
GeneralGreat Job Pin
mikhaelb11-Dec-03 11:35
Membermikhaelb11-Dec-03 11:35 
GeneralRe: Great Job Pin
retZ12-Dec-03 4:33
MemberretZ12-Dec-03 4:33 
GeneralRe: Great Job Pin
mikhaelb12-Dec-03 4:48
Membermikhaelb12-Dec-03 4:48 
GeneralRe: Great Job Pin
retZ29-Dec-03 16:11
MemberretZ29-Dec-03 16:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.