Graph Windows performance counters with MRTG

MRTG is a really great tool that creates trending graphs for just about anything. This page shows you how to use MRTG to create trend graphs for your Windows Performance counters.

Trending graphs for Disk, Memory and CPU:


Drill down into each graph and see Daily, Weekly, Monthly and Yearly graphs.



Requirements:

1. MRTG.
2. ActiveState Perl.
3. bbMrtgPerf.vbs - Save this script in the BBClient\ext directory (.cfg file maker and extension for BB).
4. getlog.pl - Save this script in MRTG's bin directory, it collects the statistics for MRTG.

Procedures:

  • Install MRTG and ActiveState Perl.
  • Create a new folder named perfgraphs under the document root of IIS.
    (default: C:\Inetpub\wwwroot)
  • Create a new folder for each machine you will monitor under the perfgraphs directory: mkdir C:\Inetpub\wwwroot\perfgraphs\machine1
    mkdir C:\Inetpub\wwwroot\perfgraphs\machine2
    mkdir C:\Inetpub\wwwroot\perfgraphs\...

  • Launch PerfMon and create a new log for each machine:




  • Add the counters that you're interested in graphing.



  • Click the "Log Files" tab and set the file type to "Text File (Comma delimited)".
  • Click the "Configure" button and define the correct Location.



  • Click the "Schedule" tab, Start log immediately, and, Start a new log file:



  • Click the "OK" button and you've got your first performance monitor log file that will collect performance data every 15 seconds for a very long time.



    Create the MRTG configuration file

    Now that you're collecting performance data in a comma sepeated file you can use MRTG to create really cool looking graphs on that data. To do so, you must create an MRTG configuration file and you'll need a script to use as an extension for Big Brother.

    Here's a script to create the MRTG config file and an extension for Big Brother rolled up into one download.

  • Save the bbMrtgPerf.vbs script in the BBClient %BBHOME%\ext directory.

    (default: C:\Program Files\Quest Software\Big Brother\BBNT\ext)

  • Edit the CONFIGURATION section in the script.
  • Execute the script with three arguments, like:

    <script name> <path to .csv file> <.csv file name> <machine name>

    bbMrtgPerf.vbs C:\Inetpub\wwwroot\PERFGRAPHS\machine1 machine1_000001.csv machine1



    Executing that command will create a machine1.cfg file and machine1.html file in the directory specified.

  • Now, run MRTG against the newly created machine1.cfg file three (3) times, the first two (2) executions will output STDERR, like:



    mrtg.pl C:\Inetpub\wwwroot\PERFGRAPHS\machine1\machine1.cfg
    That's it, you're creating trending graphs on Performance counter data with MRTG. Look in the machine1 directory and you'll see a bunch of files and images.

    Now you need to routinely execute the mrtg.pl script against your configuration file so the graphs will continue to update. To do this, I recommend creating a .vbs script and have Task Scheduler execute the script every minute, something like:

    Const HIDDEN_WINDOW = 12

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objStartup = objWMIService.Get("Win32_ProcessStartup")

    Set objConfig = objStartup.SpawnInstance_
    objConfig.ShowWindow = HIDDEN_WINDOW
    Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    errReturn = objProcess.Create("cmd.exe /c C:\mrtg-2.16.2\bin\mrtg.pl C:\Inetpub\wwwroot\PERFGRAPHS\machine001\machine001.cfg", null, objConfig, intProcessID)


    Download example VBScript machine001.vbs

    Save the .vbs file in the MRTG WorkDir (C:\Inetpub\wwwroot\PERFGRAPHS\machine1) and run it from Task Scheduler:

  • Launch Task Scheduler, right click in the pane and create a new task:



  • Give the new Task a name (bbMrtg) and double click it to open its Properties. Click the "Browse" button and navigate to the .bat file.



  • Click the "Schedule" tab. The Task should run every day starting at 0000 (12:00 AM) and run every minute until 2359 (11:59 PM).



  • So, now what? you've installed MRTG, ActiveState Perl, created performance counter log files, ran mrtg.pl against the configuration file, and, I've got graphs from the data in those log files. Now you need to put it all together with Big Brother. To do so:

  • Add the bbMrtgPerf.vbs script to the BBClient configuration editor, then Save, Stop and Start.