|
|||
|
|||
![]() |
MRTG (Multi Router Traffic Grapher) is an open source tool developed by Tobias Oetiker. It was originally designed to monitor traffic load on network links, but has the ability to use External Monitoring Scripts to monitor almost anything. In this case, it functions as a data collector, storage repository, and graph generator for use with WebInject. MRTG generates HTML pages containing PNG images which are regularly updated to provide a visual representation of the stats (response times) we are monitoring. This provides graphical trending of time-series data showing Daily, Weekly, Monthly, and Yearly statistics.
For information on MRTG, visit http://www.mrtg.org
WebInject has its own data collection and graphing capabilities. However, they are designed for ad hoc monitoring and are not very useful for graphical trending of web service-levels over a long period of time.
Alternately, WebInject can run in a mode that allows it to be used as an MRTG External Monitoring Script (plugin). This enables us to leverage MRTG's data collection, storage repository, and graph generating capabilities for use with WebInject as a solution to monitor and store web service-level history and trends.
First you must install WebInject and the necessary Perl modules. See the WebInject Build page for help getting it setup.
Then you have to modify the config.xml and add this line in it to enable the MRTG plugin mode:
<reporttype>mrtg</reporttype>
Note: you may also create an alternate config file that you can then specify on the command line used to call webinject.pl
This will modify the output of WebInject to be compatible with MRTG.
Here is an example config file (we will refer to it as myconfig.xml in later examples) which is useable with MRTG:
<testcasefile>MyApplication.xml</testcasefile>
<reporttype>mrtg</reporttype>
(see the WebInject manual for a full list of config settings that are available)
Now you would setup a test case file for WebInject to run. You may use complex test case files consisting of multiple tests and verifications chained together, or you may use a simple test case to act as a probe. Here is a minimal MyApplication.xml test case file for a sample web application:
<testcases>
<case
id="1"
description1="sample login probe for WebInject Test Site"
url="http://www.webinject.org/testsite/processlogin.cgi"
method="post"
postbody="username=foo&passwd=welcome&SUBMIT=Login"
verifypositive="successful"
verifynegative="fail"
/>
</testcases>
These instructions assume you already have MRTG setup correctly. I use it on a GNU/Linux system, and it was trivial to install.
For a listing of all the configuration options available, see the MRTG Configuration Reference.
Each monitoring target must be identified by a unique name. This name must be appended to each parameter belonging to the same target. The name will also be used for naming the generated webpages, logfiles, and images for this target. In our example, our target is named 'myapplication'.
For setting up MRTG with WebInject, the MRTG configuration settings I use are:
Here is the sample mrtg.cfg file I use with WebInject:
WorkDir: /var/www/mrtg
RunAsDaemon: yes
Interval: 5
Target[myapplication]: `/usr/local/bin/webinject.pl -c myconfig.xml`
MaxBytes[myapplication]: 180
Options[myapplication]: gauge,growright,nopercent,noo,pngdate,nolegend,nobanner
XSize[myapplication]: 600
YSize[myapplication]: 175
PNGTitle[myapplication]: WebInject Response Times
LegendI[myapplication]: resp:
Ylegend[myapplication]: seconds
ShortLegend[myapplication]: s
Title[myapplication]: WebInject Response Time Analysis
PageTop[myapplication]: <h1>Web Service-Level Monitor - MyApplication</h1>
<h2>WebInject Response Time Analysis</h2>
We can also add some CSS to the generated HTML header to style the output page a little better. Here is the final mrtg.cfg file with this added:
WorkDir: /var/www/mrtg
RunAsDaemon: yes
Target[myapplication]: `/usr/local/bin/webinject.pl -c myconfig.xml`
MaxBytes[myapplication]: 180
Options[myapplication]: gauge,growright,nopercent,noo,pngdate,nolegend,nobanner
XSize[myapplication]: 600
YSize[myapplication]: 175
LegendI[myapplication]: resp:
Ylegend[myapplication]: seconds
ShortLegend[myapplication]: s
Title[myapplication]: WebInject Response Time Analysis
PageTop[myapplication]: <h1>Web Service-Level Monitor - MyApplication</h1>
<h2>WebInject Response Time Analysis</h2>
AddHead[myapplication]: <style type="text/css">
body {
background-color: #EFEFEF;
color: #000000;
font-family: sans-serif;
font-size: 12px;
}
h1 {
background-color: #CCCCCC;
font-size: 18px;
font-weight: bold;
}
h2 {
font-size: 16px;
font-weight: bold;
}
</style>
Below is a screenshot of the sample output produced by our MRTG/WebInject setup. It shows trends in response times of our [very slow] web service with several days of data collected.
MRTG Sample output:
(click image to enlarge)
You may also view the complete sample output (web page with embedded images).