One of the fun things about being a computer geek is showing off with multiple displays going on all at once.
These might include scrolling text across various windows, and a second screen full of real-time graphs rolling from right to left, showing every last detail about the status of every computer system on the network – CPU usage, battery levels of all of the laptops, and remaining hard drive space on all systems.
Wouldn’t it be cool to have an application that would offer such a display?
We’ve covered a number of programs that provide some real-time status displays like that, like SpeedFan that Kyle and Guy covered. The most elaborate tool for viewing all of your computer information is probably Speccy, which Karl covered.
The problem with all of these is that they either offer too much or too little information. Maybe there are a few things you want to track on your network or your computer system, but you don’t want to have to dig through all of that other stuff. What if you could customize your own computer monitoring system using Windows Script, and then display the details in a really cool, real-time charting system that is open-source and absolutely free?
Developing Your Own Cool Real-Time Statistics
There are two stages to doing this. You don’t have to be a programming expert. Once you understand how to go about obtaining data from your computer (or any computer on your network) using Windows Script, you’ll be able to build this system to display whatever you like, and only what you want.
The following script will query your computer system for the current CPU load in percentages.
<script type="text/javascript" language="VBScript">// <![CDATA[
Option Explicit
On Error Resume Next
Dim oFSO, sFile1, oFile1, sFile2, oFile2, sFile3, oFile3, sText
Dim colResults, objResult, strQuery
Dim strResults
Dim x
Set Shell = wscript.createObject("wscript.shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFile1 = "CPULoad.csv"
sFile2 = "DriveSpace.csv"
sFile3 = "BatteryStatus.csv"
'***Open New File to write CPU Load***
Set oFile1 = oFSO.CreateTextFile(sFile1, 1)
'Define the WMI query
strQuery = "SELECT * FROM Win32_Processor"
' Run the query
Set colResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery )
'Identify the CPU load
For Each objResult In colResults
strResults = CStr(objResult.LoadPercentage)
Next
oFile1.WriteLine strResults
oFile1.Close
Set oFile1 = Nothing
set colResults = Nothing
strResults = ""
The key lines here are the select statement that looks at “Win32_Processor”, and the “objResult.LoadPercentage” line, which extracts the CPU load percentage from the system results. Finally, as you can see toward the bottom of the code, the data that’s extracted gets written to a csv file.
After creating the file and writing one line, the next step is to create a loop that continues polling the computer system and updating the csv data file with updated data. Here’s what that loop looks like:
'***Write New CPU Load every 5 seconds***
For x = 1 to 50
WScript.Sleep 5000
'***Update CPU Load File***
Set oFile1 = oFSO.OpenTextFile(sFile1,8,1)
'Define the WMI query
strQuery = "SELECT * FROM Win32_Processor"
' Run the query
Set colResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery )
'Identify the CPU load
For Each objResult In colResults
strResults = CStr(objResult.LoadPercentage)
Next
oFile1.WriteLine strResults
oFile1.Close
Set oFile1 = Nothing
set colResults = Nothing
strResults = ""
Next
This will loop 50 times, waiting 5 seconds between each system query and updating the data file. You could use a while loop to make it an infinite loop if you want and just have it constantly running in the background, but for this example I’m using a limited loop that runs for just over 4 minutes. Here’s what the output file looks like after the script has run for a while.
This is a cool system to query system information for data and then output that info to a constantly-updated text file. This gives you real-time information about anything the Windows WMIC system has available. Just to give you a glimpse of what sort of information is available, take a look at the Microsoft Technet page on WMIC – it’s pretty impressive.
But the real coolness-factor comes from using LiveGraph – an open-source plotting tool that will read in the real-time data you’re writing to the CSV files, and display those in an updated graph display.
When you install and run LiveGraph, you just tell it what CSV file to query, and move the slider over to the left to have the program check the data file every 10 seconds or so.
Here is what LiveGraph looks like after the windows script above has been running for a couple of minutes. LiveGraph updates automatically and as more data gets added to the file, the chart scrolls across the screen with the latest CPU load.
Once you’ve gotten this far, you can fill a whole screen up with cool real-time graphs of whatever information you’d like, by adding additional sections to your windows script that query other information about your computer or any computer on your network. For example, I added the following section to query the system for the current battery level of my laptop.
'***Open New File to write Battery Level***
Set oFile3 = oFSO.CreateTextFile(sFile3, 1)
'Define the WMI query
strQuery = "SELECT * FROM Win32_Battery"
' Run the query
Set colResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery )
'Identify the Battery Level
For Each objResult In colResults
strResults = CStr(objResult.EstimatedChargeRemaining)
Next
oFile3.WriteLine strResults
oFile3.Close
Set oFile3 = Nothing
set colResults = Nothing
strResults = ""
After adding another section to monitor the realtime level of my hard drive, I finally had three data files accumulating realtime data about my systems.
The beauty here is that you can customize the system with whatever you like – it doesn’t have to be computer information, you can poll network status, ping computers on your network, query HTML files and extract information that you can display in a real-time graph on your screen.
I love the display, and now kick off the windows script on my PC startup, and just make it run in an infinite loop. For now it’s providing system info about all of the PCs on my network, but plan to play around with extracting real-time info about my overall network bandwidth use and information polled off the net. With VB Script and imagination, the sky’s the limit.
Give the script and LiveGraph a try, and play around with adding your own information and data to the system. What kind of cool graph displays did you come up with? Share your experiences and thoughts in the comments section below.
Similar Stuff
How To Control Running Services With The SR Command [Windows]
How To Fix Common Windows Problems In A Snap With FixWin
Speccy – An Advanced System Information Tool For Your PC
No comments:
Post a Comment
[Please do not advertise, or post irrelevant links. Thank you for your cooperation.]