[mrtg] Re: Monitoring MRTG itself

Eric Brander Eric_Mailing_List at rednarb.com
Tue Jul 1 14:47:15 MEST 2003


----- Original Message ----- 
From: "Verstrooid Profke" <profke at easynet.be>
To: <mrtg at list.ee.ethz.ch>
Sent: Monday, June 30, 2003 9:23 AM
Subject: [mrtg] Monitoring MRTG itself

>
> Hi,
>
> I'm looking into the possibility to monitor the time it takes for mrtg
> to collect its data, generate png's, ...
~snip~

I run 5 instances of MRTG simultaneously using a batch file and task
scheduler on Win2k.  In the batch file I take command line input for
which instance I want to use, and that is correlated to a particular
subdirectory.  The batch file then runs MRTG against all the .cfg files
in that subdir.  But, at the beginning and the end of the batch file I
call out to a small VB script I wrote that gets the current time and
outputs it to a temp file.  Then at the end of the batch file I run MRTG
again to graph the time difference.  Its a hodge podge of mix and match
script and stuff, but it works for me and gives me great graphs.  Below
is posted my batch file, the vbs file, one of the config files, and an
example PNG. Maybe you can extract what you need and go from there.
DISCLAIMER - your mileage may vary, and there may also be a better way
to do this. No warranty expressed nor implied!  ;-)  Also, the list may
truncate/wrap the lines, keep that in mind when reading this.

The batch file:
@echo off
CLS
IF "%1" == "" GOTO NOARG
SET CLA=%1
:Begin
cscript //nologo timer.vbs %CLA% start
echo.
Now
Echo ********* >> mrtg-%CLA%.log
Now >> mrtg-%CLA%.log
echo.
Title MRTG-%CLA% Polling...

for /f %%i in ('dir /on /b cfg-%CLA%\*.cfg') do call :run %%i

del cfg-%CLA%\*.cfg_l*

echo.
Now
Now >> mrtg-%CLA%.log
echo.
echo. >> mrtg-%CLA%.log
Echo ********* >> mrtg-%CLA%.log
cscript //nologo timer.vbs %CLA% finish
:cscript //nologo logmaint.vbs %CLA%
perl mrtg Timer-%CLA%.cfg
del Timer-%CLA%.ok
goto end

:run
echo Polling - %1
echo ---------- >> mrtg-%CLA%.log
echo Polling - %1 >> mrtg-%CLA%.log
perl mrtg cfg-%CLA%\%1 --logging mrtg-%CLA%.log --confcache-file
confcache\%1.ok
:Now >> mrtg-%CLA%.log
goto :eof

:NOARG
ECHO.
ECHO An instance number must be included on the command line.
ECHO.
ECHO Example: MRTGPoll 3
ECHO.
goto end

:end

TIMER.VBS
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set objArgs = WScript.Arguments
InstanceNumber = objArgs.item(0)
When = UCase(objArgs.item(1))

If When = "MRTG" Then Call MRTG()
If When = "START" Then Call START()
If When = "FINISH" Then Call FINISH()

Sub START()
  Dim fso, f1
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f1 = fso.OpenTextFile("timer-" & InstanceNumber & ".txt",
ForWriting, True)
  f1.WriteLine Timer
End Sub

Sub FINISH()
  Dim fso, f1
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f1 = fso.OpenTextFile("timer-" & InstanceNumber & ".txt",
ForAppending)
  f1.WriteLine Timer
End Sub

Sub MRTG()
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f1 = fso.OpenTextFile("timer-" & InstanceNumber & ".txt",
ForReading)
  StartTime = f1.ReadLine
  FinishTime = f1.ReadLine
  Elapsed = FinishTime - StartTime
  Wscript.Echo FormatNumber(Elapsed,1)
  'wscript.echo Elapsed
  wscript.echo "0"
  wscript.echo "0"
  wscript.echo "0"
  Set f1 = fso.GetFile("timer-" & InstanceNumber & ".txt")
  f1.delete
End Sub

The Config:

### Global Config Options

HtmlDir: \mrtg\www
ImageDir: \mrtg\images
IconDir: \mrtg\images
LogDir: \mrtg\log
ThreshDir: \mrtg\thresh

### Global Defaults

Background[_]: #FFFFE8
ThreshProgO[_]: \mrtg\thresh\NotifyError.Bat
ThreshProgOKO[_]: \mrtg\thresh\NotifyOK.Bat
Unscaled[_]: dmwy
XSize[_]:600

########################################


Target[timer_1]: `cscript //nologo timer.vbs 1 mrtg`
Directory[timer_1]: timer
Options[timer_1]: growright, nobanner, gauge, unknaszero
WithPeak[timer_1]: wmy
MaxBytes[timer_1]: 60
AbsMax[timer_1]: 1000000
YTics[timer_1]: 8
Legend2[timer_1]:
Legend1[timer_1]: Polling Time - Instance 1
Legend3[timer_1]:
Legend4[timer_1]:
LegendO[timer_1]:
LegendI[timer_1]: Seconds
YLegend[timer_1]: Seconds
ShortLegend[timer_1]: Seconds
Colours[timer_1]: BLUE#0066ff,RED#cc0000,DARK GREEN#009900,VIOLET#ff00ff
Title[timer_1]: Polling Time - Instance 1
PageTop[timer_1]: <H1><font color="#0000FF">Polling Time - Instance
1</font></H1>


Eric Brander
Eric_Mailing_List at rednarb dot com


-- Attached file removed by Ecartis and put at URL below --
-- Type: image/png
-- Size: 2k (2455 bytes)
-- URL : http://www.ee.ethz.ch/~slist/p/timer_1-day.png


--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list