I used to play with cacti, creating my own scripts, data input methods, data sources, graphs items and then graphs, but it was long way to obtain a single graph.
A smarter way is to use « SNMP – Generic OID Template » that appeared in cacti.
Let’s see an example : I want to graph the number of spams I’ve received during the last 24 hours. Counting is easy, I’ve just to find all files more recent than 24 hours in my IMAP folder « spam » (spamassassin does a very good job !). But I had to face security considerations, because apache user had to access my maildir !
It’s much simpler to expose this number via snmp, and then to create a simple graph based on Cacti « Generic OID » template. Note that SNMP is only accessible from my LAN, and the number of spams I’ve received is not very sensitive data. So let’s go:
- Create the script /usr/local/bin/countspam.sh
#!/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin find /home/cyril/Maildir/.SPAM/cur/ -ctime -1 | wc -l
- Configure snmpd.conf to run this script and return the result
# Extensible sections. exec .220.127.116.11.4.1.15555.1 countspam.sh /usr/local/bin/countspam.sh
- Test the query. Note that the interesting value is .18.104.22.168.4.1.15555.101.1
root:/etc # snmpwalk -c public -v2c localhost .22.214.171.124.4.1.15555.1 SNMPv2-SMI::enterprises.155126.96.36.199 = INTEGER: 1 SNMPv2-SMI::enterprises.155188.8.131.52 = STRING: "countspam.sh" SNMPv2-SMI::enterprises.155184.108.40.206 = STRING: "/usr/local/bin/countspam.sh" SNMPv2-SMI::enterprises.155220.127.116.11 = INTEGER: 0 SNMPv2-SMI::enterprises.15518.104.22.168 = STRING: "40" SNMPv2-SMI::enterprises.15522.214.171.124 = INTEGER: 0 SNMPv2-SMI::enterprises.155126.96.36.199 = ""
- Connect to cacti console, click « New graph », select your host and « SNMP – Generic OID Template »
- Enter the title, OID .188.8.131.52.4.1.15555.101.1 and choose a (fun) color
- Your graph is now ready :