Section 12.4. Other Data-Gathering Applications


12.4. Other Data-Gathering Applications

What if you need to monitor devices on your network that don't support SNMP? MRTG is up to the task. For example, you may have a Perl script that gathers usage statistics from some device that doesn't support SNMP. How can you collect and graph this data? Let's make this more concrete. Assume that you have the following script, /usr/local/scripts/hostinfo.pl, which reports the number of users and the number of processes on the system:

     #!/usr/bin/perl     $who = "/usr/bin/who | wc -l";     $ps = "/bin/ps -ef h | wc -l";     chomp($numUsers = int( '$who' ));     chomp($numProcesses = int( '$ps' ));     print "$numUsers\n";     print "$numProcesses\n";     #     # The following code prints the system uptime and the hostname. These two     # items need to be included in every script that you write and should be the     # very last thing that is printed.     #

Figure 12-4. Daily, weekly, monthly, and yearly graphs for number of users and processes


     chomp($uptime =  '/usr/bin/uptime' );     print "$uptime\n";     chomp($hostname =  '/bin/hostname' );     print "$hostname\n"; 

This script prints four variables: the number of users and the number of processes (the data we want MRTG to collect), and the system uptime and hostname (required by MRTG). To get MRTG to run this script, we'll have to edit mrtg.cfg by hand. The modification is actually simpler than our previous example. Here's the new entry to mrtg.cfg, with the changes shown in bold:

     Target[linuxserver.users]: '/usr/bin/perl /usr/local/bin/hostinfo.pl'     MaxBytes[linuxserver.users]: 512     Options[linuxserver.users]: gauge     Title[linuxserver.users]: linuxserver (linuxserver): Number of     users and processes     YLegend[linuxserver.users]: Users/Processes     LegendI[linuxserver.users]: &nbsp;Users:     LegendO[linuxserver.users]: &nbsp;Processes:     PageTop[linuxserver.users]: <H1>Number of users and processes      </H1>     <TABLE>        <TR><TD>System:</TD>     <TD>box in Atlanta,GA</TD></TR>        <TR><TD>Maintainer:</TD> <TD>"kjs@guarded.net"</TD></TR>     </TABLE> 

Note the addition of '/usr/bin/perl /usr/local/bin/hostinfo.pl' to the Target command. This line tells MRTG to run the script or program between the backticks. The rest should be familiar. MRTG interprets the first value that the script prints (the number of users) as its input data; the second value (the number of processes) is the output data. When it generates graphs, it applies the appropriate input and output legends (LegendI and LegendO).




Essential SNMP
Essential SNMP, Second Edition
ISBN: 0596008406
EAN: 2147483647
Year: 2003
Pages: 165

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net