Monitor System Information
A program to monitor and collect basic system information from remote machines.
Introduction
Monitor Center is a system designed to help you control and monitor your computers in a local network. The system allows you to see, in real time, useful information about any of your computers using an easy interface that can be suited to your own needs.
This article supplies examples of how to access different information on the Windows Operating System, such as process information, performance counters, and basic system information.
Background
The program uses the .NET Framework libraries in order to get the requested information.
Using the code
How can you use the program?
After you unzipp the demo file, copy MonitorCenter1.0.exe from the Server folder to any location on the server machine. This EXE is the central interface of the system from which you can perform all your actions on each one of the clients you wish to monitor (including the machine on which MonitorCenter1.0.exe is located). After this, copy the folder named Client to a location of your choice.
You can read the User Guide document that is included in the demo zip file for further instructions about using the program.
Now, the system is ready for use; just run both the server and client exe files! Here are some examples of collecting the required information.
Reading the processes information:
using System.Diagnostic;
Process[] ProcessList = Process.GetProcesses();
foreach (Process CurrProcess in ProcessList)
{
Console.WriteLine("Process Name:" + CurrProcess.ProcessName);
Console.WriteLine("Main Module FileName:" + CurrProcess.MainModule.FileName);
Console.WriteLine("Start Time:" + CurrProcess.CurrProcess.StartTime);
}
The process owner, for example, is not part of the Process
class, so we get this data from WMI:
using System.Management;
public string GetProcessOwner(int processID)
{
string owner = string.Empty;
string queryString = "Select * From Win32_Process Where ProcessID = " + processID;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(queryString);
ManagementObjectCollection processList = searcher.Get();
foreach (ManagementObject currentProcess in processList)
{
string[] argList = { string.Empty };
int returnValue = Convert.ToInt32(currentProcess.InvokeMethod("GetOwner", argList));
if (returnValue == 0)
owner = argList[0];
}
return owner;
}
In order to get information of the Operating System performance counters, such as CPU usage, use the following code:
using System.Diagnostic;
PerformanceCounter CurrCounter = new PerformanceCounter("Processor%",
"ProcessorTime", "_Total");
int CPUTimeValue = CurrCounter.NextValue();
The information we collected was presented in line graphs which we built using ZedGraph. ZedGraph is an open source which you can download for free and use it to build any kind of graph you like.
All the above code examples are parts of the project source file.
Points of interest
Not all users have permissions to access system information. Moreover, sometimes, even the system administrator cannot access certain data. Use try
and catch
blocks when accessing information of the Operating System.