Archives par étiquette : cacti

Cacti simple oid

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 .1.3.6.1.4.1.15555.1 countspam.sh /usr/local/bin/countspam.sh
  • Test the query. Note that the interesting value is .1.3.6.1.4.1.15555.101.1
root:/etc # snmpwalk -c public -v2c localhost .1.3.6.1.4.1.15555.1
SNMPv2-SMI::enterprises.15555.1.1.1 = INTEGER: 1
SNMPv2-SMI::enterprises.15555.1.2.1 = STRING: "countspam.sh"
SNMPv2-SMI::enterprises.15555.1.3.1 = STRING: "/usr/local/bin/countspam.sh"
SNMPv2-SMI::enterprises.15555.1.100.1 = INTEGER: 0
SNMPv2-SMI::enterprises.15555.1.101.1 = STRING: "40"
SNMPv2-SMI::enterprises.15555.1.102.1 = INTEGER: 0
SNMPv2-SMI::enterprises.15555.1.103.1 = ""
  • Connect to cacti console, click « New graph », select your host and « SNMP – Generic OID Template »
  • Enter the title, OID .1.3.6.1.4.1.15555.101.1 and choose a (fun) color
  • Your graph is now ready :

spam-count

hddtemp template for cacti

I’ve made a template to query hddtemp deamon and graph disks temperature.
Tested with cacti 0.8.6h on fc5, debian and gentoo. It uses only php core functions, no extra librairies are needed.

graph_image.php

INSTALLATION :

  • Install and configure hddtemp daemon
  • Test it with « telnet <host> 7634 » from your cacti box
  • Output should be similar to :

"|/dev/hda|IBM-DJNA-371350|47|C||/dev/hdc|Maxtor 6Y080L0|44|C|"

  • Copy hddtemp.xml to resources/script_queries directory
  • Copy hddtemp.php to scripts directory
  • Import template file cacti_template_linux_hddtemp_disk_temperature.xml
  • Add « Linux – hddtemp – disk temperature » data query to your host
  • Create new graph for this host and select disks

GROUPING GRAPHS :

If you want to group several disks on the same graph :

  • Import cacti_graph_template_linux_hddtemp_disk_temperature_2x.xml or cacti_graph_template_linux_hddtemp_disk_temperature_9.xml templates
  • Create a graph for each disk as described above
  • Create a graph for your host using 2x or 9x template, let fields empty
  • Edit the graph and select data sources previously created
  • You can delete single-disk graphs but not data sources

NOTE : You need exactly 2 or 9 disks, or you’ll have to modify the template.

DOWNLOAD : cacti-linux-hddtemp-1.0.tar.gz