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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access