<< Prev  |  TOC  |  Front Page  |  Talkback  |  FAQ  |  Next >>
...making Linux just a little more fun!
A quick and Dirty guide to extending snmp
By David Dorgan

A quick and Dirty guide to extending snmp

Monitoring and Graphing Applications with SNMP and MRTG.

There are two basic sections in this article, first will be checking
services or processes via net-snmp.

First off download net-snmp from net-snmp.org, a simple
./configure ; make ; make install should do the trick in most cases.
After this you should run sudo snmpconf, to create your snmpd.conf
file, which will contain your community names, location etc...
Then with the basic configuration you could start the snmpd with
sudo snmpd, or sudo snmpd -r which enables net-snmp to drop most
privileges just after startup.

In this default setting, with a default configuration,
you could do something like snmpwalk -v 1 -c public localhost , to see
some of the built-in settings. Now to get to the interesting section,
let’s say you want to monitor an application you just wrote...
let’s say you want to check if port 25 is up, via snmp....
You could write a simple python application[0], which returns 0
for a success, or 1 for a failure...

(In real life you would probably just do this from a remote host, but this
is just a simple example which can be expanded to your application).

Now to monitor this event, in your /etc/snmpd.conf add a line like...
exec check-smtp /software/snmp/check-smtp.py

A oversimplified explanation of the number would be, means enterprise, 5000 would be your organisations MIB
number, and 100 would be the specific OID. For more information on getting
an organisation private enterprise number, you should see

Now if you type snmpwalk -v 1 -c public localhost
you will see not just the reply, but all objects within the OID.
If you wanted to be specific (which you may need to do for snmp managers
or mrtg...you would have something like snmpwalk -v 1 -c public localhost

Or graph something (anything) on a remote machine with snmp and mrtg?

Now let’s say, you wanted a simple mrtg graph, which only checked for the amount
of threads in a mysql database, which while useful, is once again a pretty
simple example, let’s say you didn’t mind spawning a shell and executing a command,
you might do something like mysqladmin status | awk {’print $4’} ...
which is fairly system unfriendly, but there isn’t much point presenting a robust
c application in this case. Now in /etc/snmpd.conf add

exec mysql-thread-load /software/snmp/mysql-thread-load.sh

inside the file have
mysqladmin status | awk {’print $4’}

and make sure it’s executable by the calling process.

Here is a sample partial mrtg config[1].

The reason in Target that you have specified the number twice, breaking it up with an & sign,
is that mrtg generally expects two inputs, one for incoming and one for outgoing, this way
it just uses the same reply for both. Of course you could monitor something like mysql threads,
and load average, and they could be graphed in the same picture, which can be interesting
for correlation between application and system load.

import socket
import time

HOST = ’localhost’
PORT = 25

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
print ’0’
except socket.error:
print ’1’;

options[mysqlconnections]: nobanner,absolute,gauge,growright,nopercent
Title[mysqlconnections]:Mysql Threads
PageTop[mysqlconnections]: <h1>Mysql Threads</h1>
MaxBytes[mysqlconnections]: 1000
YLegend[mysqlconnections]: connections
ShortLegend[mysqlconnections]: connections
LegendI[mysqlconnections]: connections:
Legend1[mysqlconnections]: connections
Step[mysqlconnections]: 12

$Id: dirty-snmp.html,v 1.4 2003/08/30 15:00:35 davidd Exp $


[BIO] David has been a very productive writer and plans to contribute more of his work in the future.

Copyright © 2003, David Dorgan. Copying license http://www.linuxgazette.com/copying.html
Published in Issue 96 of Linux Gazette, November 2003

<< Prev  |  TOC  |  Front Page  |  Talkback  |  FAQ  |  Next >>