Updated on 18 Jan, 2006 by SuSE 10.0
Multi Router Traffic Grapher# # First, map the community name "public" into a "security name" # sec.name source community com2sec public default public # Second, map the security name into a group name. # groupName securityModel securityName group public v1 public group public v2c public group public usm public # Third, create a view for us to let the group have rights to: # name incl/excl subtree mask(optional) view all included .1 # Finally, grant the group read-only access to the systemview view. # group context sec.model sec.level prefix read write notif access public "" any noauth exact all all all # System contact information # syslocation xxxxxxxx syscontact foo@host

gw(config)#snmp-server community public RO
# snmpwalk -v 1 192.168.1.100 -c public | less SNMPv2-MIB::sysDescr.0 = STRING: Hardware: x86 Family 6 Model 9 Stepping 5 AT/AT CO MPATIBLE - Software: Windows 2000 Version 5.1 (Build 2600 Uniprocessor Free) SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.311.1.1.3.1.1 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (80732) 0:1 SNMPv2-MIB::sysContact.0 = STRING: SNMPv2-MIB::sysName.0 = STRING: TS-NEC SNMPv2-MIB::sysLocation.0 = STRING: SNMPv2-MIB::sysServices.0 = INTEGER: 76 IF-MIB::ifNumber.0 = INTEGER: 4 ....
# rpm -ihv mrtg-2.12.2-2.i586.rpm
# mkdir /srv/www/htdocs/mrtg
#!/bin/bash
# host list
HOSTLIST="
192.168.0.1
192.168.0.2
"
# Make configuration file
for HOST in $HOSTLIST
do
/usr/bin/cfgmaker \
--ifref=eth \
--global 'WorkDir: /srv/www/htdocs/mrtg' \
--global 'Options[_]: bits,growright' \
--output /etc/mrtg/$HOST.cfg \
public@$HOST
done
This example monitor two devices (192.168.0.1, 192.168.0.2) and makes two configuration files (192.168.0.1.cfg and 192.168.0.2.cfg)
#!/bin/bash
DIRCFG=/etc/mrtg
DIRHTML=/srv/www/htdocs/mrtg
LISTCFG="
192.168.0.1.cfg
192.168.0.2.cfg
"
for CFG in $LISTCFG
do
env LANG=C /usr/bin/mrtg $DIRCFG/$CFG
done
# Make index file
cd $DIRCFG
/usr/bin/indexmaker --columns=1 $LISTCFG > $DIRHTML/index.html
... 0-59/5 * * * * root /etc/mrtg/mrtg.cron >/dev/null 2>&1
Order deny,allow
# Deny from all
Allow from localhost
# Allow from .example.com
# This section creates CPU Load monitoring ### CPU Load Average ### Target[cpu_hostname]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:public@localhost MaxBytes[cpu_hostname]: 100 Unscaled[cpu_hostname]: dwmy Options[cpu_hostname]: gauge, absolute, growright, noinfo, nopercent YLegend[cpu_hostname]: CPU Load(%) ShortLegend[cpu_hostname]: (%) LegendI[cpu_hostname]: 1min ave LegendO[cpu_hostname]: 5min ave Legend1[cpu_hostname]: 1min ave(%) Legend2[cpu_hostname]: 5min ave(%) Title[cpu_hostname]: CPU Load ($HOST) PageTop[cpu_hostname]: <H1>CPU Load Average -- suse10</H1>
#!/usr/bin/perl
# It assumes that the command output(df -kl) looks like this:
# Filesystem 1k-blocks Used Available Use% Mounted on
# /dev/md0 95645100 30401312 64272080 33% /
# /dev/hde1 14119 1159 12231 9% /boot
#
# In which case, this script returns :
# 95659219
# 30402503
# when run.
foreach $filesystem (`df -kl | grep -v "Filesystem"`)
{
@df = split(/\s+/,$filesystem);
$total += $df[1];
$usage += $df[2];
}
print "$usage\n";
print "$usage\n";
print "$total\n";
# chmod 755 df.pl
service df
{
socket_type = stream
protocol = tcp
wait = no
user = nobody
bind = 127.0.0.1
server = /usr/local/sbin/df.pl
}
df 9047/tcp # df
# /etc/init.d/xinetd restart
# /usr/bin/netcat localhost df 3479420 3479420 9931728
# Disk usage monitoring Target[disk_hostname]: `/usr/bin/netcat localhost df` Title[disk_hostname]: Disk Usage -- suse10 Unscaled[disk_hostname]: dwym MaxBytes[disk_hostname]: 9931728 PageTop[disk_hostname]: <H1>Disk Usage -- suse10</H1> kmg[disk_hostname]: KB,MB,GB LegendI[disk_hostname]: Used Disk Space LegendO[disk_hostname]: Total Disk Space Legend1[disk_hostname]: Used Disk Space Legend2[disk_hostname]: Total Disk Space YLegend[disk_hostname]: Megabytes ShortLegend[disk_hostname]: Options[disk_hostname]: gauge, growright, noinfo
#!/usr/bin/perl
foreach $_ (`/usr/bin/sar -r 1 2 | grep "Average"`)
{
($average, $kbmemfree, $kbmemused, $memused, $kbmemshrd, $kbbuffers, $kbcached, $kbswpfree, $kbswpused, $swpused) = split(/\s+/);
print $kbmemused - $kbbuffers . "\n";
print $kbmemused . "\n";
print $kbmemused + $kbmemfree . "\n";
}
# chmod 755 memory.pl
service memory
{
socket_type = stream
protocol = tcp
wait = no
user = nobody
bind = 127.0.0.1
server = /usr/local/sbin/memory.pl
}
memory 9057/tcp # memory
# /etc/init.d/xinetd restart
# /usr/bin/netcat localhost memory 203578 308974 312960
# Memory usage monitoring Target[memory_hostname]: `/usr/bin/netcat localhost memory` MaxBytes[memory_hostname]: 312960 Unscaled[memory_hostname]: dwym YLegend[memory_hostname]: Memory Usage ShortLegend[memory_hostname]: kmg[memory_hostname]: kB,MB kilo[memory_hostname]: 1024 LegendI[memory_hostname]: App Data LegendO[memory_hostname]: Memory Used Legend1[memory_hostname]: App Data Legend2[memory_hostname]: Memory Used Options[memory_hostname]: gauge, growright, noinfo Title[memory_hostname]: Memory Usage -- suse10 PageTop[memory_hostname]: <H1>Memory Usage -- suse10</H1>
#!/usr/bin/perl
foreach $_ (`/usr/bin/sar -r 1 2 | grep "Average"`)
{
($average, $kbmemfree, $kbmemused, $memused, $kbbuffers, $kbcached, $kbswpfree, $kbswpused, $swpused, $kbswpcad) = split(/\s+/);
print $kbswpcad . "\n";
print $kbswpused . "\n";
print $kbswpused + $kbswpfree . "\n";
}
# chmod 755 swap.pl
service swap
{
socket_type = stream
protocol = tcp
wait = no
user = nobody
bind = 127.0.0.1
server = /usr/local/sbin/swap.pl
}
swap 9058/tcp # swap
# /etc/init.d/xinetd restart
# /usr/bin/netcat localhost swap 40 3104 706820
# Swap usage monitoring Target[swap_hostname]: `/usr/bin/netcat localhost swap` MaxBytes[swap_hostname]: 706820 Unscaled[swap_hostname]: dwym YLegend[swap_hostname]: Swap In Use kmg[swap_hostname]: kB,MB kilo[swap_hostname]: 1024 LegendI[swap_hostname]: Cached Swap LegendO[swap_hostname]: Swap Used Legend1[swap_hostname]: Cached Swap Legend2[swap_hostname]: Swap Used Options[swap_hostname]: gauge, growright, noinfo ShortLegend[swap_hostname]: Title[swap_hostname]: Swap Usage -- suse10 PageTop[swap_hostname]: <H1>Swap Usage -- suse10</H1>
# rpm -ihv mtr-0.69-4.i586.rpm
#!/usr/bin/perl
# Usage: perl.pl host
@result = split(/\s+/,`/usr/sbin/mtr -r $ARGV[0] | tail -n 1`);
if ($result[7] != 0) {
print $result[7] / $result[8] * 100 . "\n";
print 100-$result[3] . "\n";
} else {
print "0\n";
print "0\n";
}
# chmod 755 ping.pl
# Network Availability Target[ava_hoge]: `/usr/local/sbin/ping.pl www.hoge.com` MaxBytes[ava_hoge]: 100 Unscaled[ava_hoge]: dwym YLegend[ava_hoge]: Availability ShortLegend[ava_hoge]: (%) LegendI[ava_hoge]: Stability (best/worst) LegendO[ava_hoge]: Availability Legend1[ava_hoge]: Stability (best/worst) Legend2[ava_hoge]: Availability Options[ava_hoge]: gauge, absolute, growright, noinfo, nopercent Title[ava_hoge]: Availability -- www.hoge.com PageTop[ava_hoge]: <H1>Availability -- www.hoge.com</H1>