Friday, January 21, 2011

collectd-mod-exec Part 2

Part1

My router SBC is equipped with two temperature sensors to monitor cpu and board temperatures. Executing 'sensors' command produces the following result:
root@Alix:~# sensors
lm86-i2c-0-4c
Adapter: CS5536 ACB0
temp1:       +36.0 C  (low  =  +0.0 C, high = +70.0 C)
                      (crit = +85.0 C, hyst = +75.0 C)
temp2:       +42.5 C  (low  =  +0.0 C, high = +70.0 C)
                      (crit = +85.0 C, hyst = +75.0 C)
With a bit of the script-fu I'm stripping temperature values and feeding them into the database:


root@Alix:~# cat /mnt/sd/bin/tmpcollect.sh
#!/bin/sh
  
logger "*** tmpcollect script is started ***"
HOST=$COLLECTD_HOSTNAME
INTERVAL=$COLLECTD_INTERVAL
[ -z "$INTERVAL" ] && INTERVAL=10
INTERVAL=$(awk -v i=$INTERVAL 'BEGIN{print int(i)}')
while sleep $INTERVAL; do
  cpuvalue=`sensors -A | sed -r -n -e 's/temp2:[[:blank:]]*?([[:graph:]]*?)[[:blank:]].*/\1/;s/^\+//gp'`
  boardvalue=`sensors -A | sed -r -n -e 's/temp1:[[:blank:]]*?([[:graph:]]*?)[[:blank:]].*/\1/;s/^\+//gp'`
  echo "PUTVAL \"$HOST/exec-temperature_sensors/temperature-cpu_temp\" interval=$INTERVAL N:$cpuvalue"
  echo "PUTVAL \"$HOST/exec-temperature_sensors/temperature-board_temp\" interval=$INTERVAL N:$boardvalue"
done
I'm feeding cpu and board temperature separately because "temperature" data type is defined to receive only one value. As the result I get two separate graphs for cpu and board temperatures:
[Image]

Although the result is correct the labels on both graphs aren't perfect. Additionally it would be better to have both values on the same graph.


Next time I'll explain how to add custom data types into the collectd to be able to feed any type of data and also put multiple datasets into the same graph.

No comments: