MRTG (Multi Router Traffic Grapher) is monitoring utility, which runs on many platforms and is capable of collecting and graphing statistical information such as network traffic, CPU/Memory/Disk space usage, etc. MRTG can gather information using both SNMP protocol and external scripts. Below are few pieces of my MRTG config file together with scripts, which I felt like sharing.
# # MS Win2k server monitoring # # CPU #0 # My script gets the processor load using snmpwalk. There is a bug in # MS SNMP implementation, which changes the processor OID every time SNMP # service is restarted. # My script takes care of it, until your processor is Intel based. Target[server1.cpu0]: `/usr/local/bin/mrtg/snmpcpuinfo.perl server1 community 0` # This will be created under WordDir. Comes very handy, when you have a # a handfull of servers. Directory[server1.cpu0]: server1.mydomain.com # Processor load is measured in percent, so 100 will be enough. MaxBytes[server1.cpu0]: 100 Options[server1.cpu0]: growright,integer,unknaszero,nopercent,gauge Title[server1.cpu0]: server1.mydomain.com (cpu0) YLegend[server1.cpu0]: % Used ShortLegend[server1.cpu0]: % # You can add here as many processors, as you have on your server. # # eth0 # This is the network interface of our Win2k server. The easiest way # to get the correct target is to use cfgmaker, which comes with MRTG. Target[server1.eth0]: 2:firstname.lastname@example.org Directory[server1.eth0]: server1.mydomain.com Options[server1.eth0]: nopercent,growright Title[server1.eth0]: server1.mydomain.com (eth0) # # users and processes # Actually, this is not that useful on Win server, though I added it to # have some consistency with Lin servers pages. Target[server1.userproc]: `/usr/local/bin/mrtg/snmpuserprocinfo.perl server1 community` Directory[server1.userproc]: server1.mydomain.com MaxBytes[server1.userproc]: 523444000 Options[server1.userproc]: nopercent,growright,gauge,integer Title[server1.userproc]: server1.mydomain.com (users and processes) YLegend[server1.userproc]: Processes/Users ShortLegend[server1.userproc]: # # # Disk space on drive C # The index of disk can be obtained from snmpwalk output. # Now, guess what? Win2k does not update the value of space used very # often. Actually, this value changes only when the SNMP service is # restarted. There are different ways of going around this problem. I've # decided to schedule SNMP service restarts every 10 minutes with # this .bat file. Target[server1.diskc]: `/usr/local/bin/mrtg/snmphddinfo.perl server1 community 2` Directory[server1.diskc]: server1.mydomain.com # Make sure you put a huge number in here MaxBytes[server1.diskc]: 100000000000 Options[server1.diskc]: growright,integer,unknaszero,nopercent,gauge # By default MRTG uses 1000 for Kilo. Here we change it for a second kilo[server1.diskc]: 1024 # Disk space is better viewed in Megabytes, Gigabytes, etc. kMG[server1.diskc]: M,G,T ShortLegend[server1.diskc]: Bytes # # # Linux server monitoring # # Append the following lines to your /etc/snmp/snmpd.conf and restart the # snmp daemon. Of course, you should not have hash (#) sign in front of # those lines. # ---------- # exec Load-1 /usr/bin/perl /usr/local/sbin/mrtg/loadavg.perl 1 # exec Load-5 /usr/bin/perl /usr/local/sbin/mrtg/loadavg.perl 5 # exec Procs /usr/bin/perl /usr/local/sbin/mrtg/numprocs.perl # exec MailQ /usr/bin/perl /usr/local/sbin/mrtg/mailqlen.perl # exec MailQ-Frozen /usr/bin/perl /usr/local/sbin/mrtg/mailqlen.perl frozen # ---------- # CPU #0 # Actually, I am not measuring CPU load on in Linux servers. I am pretty # satisfied with plain Load Average * 100. Target[server2.cpu0]: `/usr/local/bin/mrtg/snmploadavg.perl server2 community` Directory[server2.cpu0]: server2.mydomain.com # Actually, load average is multiplied by 100, so that the graph looks more # interesting. MaxBytes[server2.cpu0]: 10000 Options[server2.cpu0]: growright,integer,unknaszero,nopercent,gauge Title[server2.cpu0]: server2.mydomain.com (Load average) YLegend[server2.cpu0]: loadavg LegendI[server2.cpu0]: 1 min load average LegendO[server2.cpu0]: 5 min load average # You can add here as many processors, as you have on your server. # # eth0 # Network monitoring is configured exactly the same as for Win2k server. # Still running of cfgmaker is recommended. Target[server2.eth0]: 2:email@example.com Directory[server2.eth0]: server2.mydomain.com Options[server2.eth0]: nopercent,growright Title[server2.eth0]: server2.mydomain.com (eth0) # # Mailq # Monitoring of mail queue is essential, since it helps you to see a # wide range of problems with your server # I am using Exim instead of Sendmail, # so, I am sorry if you are missing mailq command. Target[server2.mailq]: `/usr/local/bin/mrtg/snmpmailq.perl server2 community` Directory[server2.mailq]: server2.mydomain.com # Change the number appropriate for your environment MaxBytes[server2.mailq]: 1000000 Options[server2.mailq]: growright,integer,unknaszero,nopercent,gauge Title[server2.mailq]: server2.mydomain.com (Mail Queue) YLegend[server2.mailq]: Messages ShortLegend[server2.mailq]: Messages LegendI[server2.mailq]: Frozen LegendO[server2.mailq]: Total # # users and processes # Pretty much the same as for Win2k server, but note that "lin" parameter # to the script. Target[server2.userproc]: `/usr/local/bin/mrtg/snmpuserprocinfo.perl server2 community lin` Directory[server2.userproc]: server2.mydomain.com MaxBytes[server2.userproc]: 523444000 Options[server2.userproc]: nopercent,growright,gauge,integer Title[server2.userproc]: server2.mydomain.com (users and processes) YLegend[server2.userproc]: Processes/Users ShortLegend[server2.userproc]: # # # Disk space on / Target[server2.disk0]: `/usr/local/bin/mrtg/snmphddinfo.perl server2 community 1` Directory[server2.disk0]: server2.mydomain.com MaxBytes[server2.disk0]: 100000000000 Options[server2.disk0]: growright,integer,unknaszero,nopercent,gauge # By default MRTG uses 1000 for Kilo. Here we change it for a second kilo[server2.disk0]: 1024 kMG[server2.disk0]: M,G,T ShortLegend[server2.disk0]: Bytes
You can get all the scripts mentioned in this article as one file.