Check_MK plugin: lmsensors
by BenV on Jun.07, 2011, under Software
On the subject of Pretty Graphs (see my earlier post), I decided to write a plugin (a.k.a. ‘Package’) for Check_MK in order to monitor (and make pretty graphs!) of the sensor output of lmsensors.
Most machines support this out of the box these days, and it’s always interesting to see the conditions of your machine. In case you don’t know, it gives the temperature and voltage of your CPU and mainboard. Thus it’s a good source for making pretty graphs
Since these plugins are very easy to install (once you’ve got check_mk up and running that is) and still nobody had written one for lmsensors, I decided to do it myself. Writing python isn’t my strongest point (yet), but these are good opportunities to learn.
One of the issues I ran into while writing the plugin was that PNP4Nagios fails on service names that have a plus character in them. For instance, I had Sensor +12V. This created the files Sensor_+12V.rrd and corresponding xml, but when one would go to the PNP4Nagios graph of that sensor it would request a file called Sensor__12V.rrd, which obviously failed.
Therefore I molested the names a bit, so your sensor might now be simply called MB12V instead of M/B+12V.
Configuration of LM-Sensors
For my plugin to work you need to make sure that you have the ‘sensors’ tool. This normally comes in a package called “lmsensors” or “lm-sensors”. Note that you obviously need some kind of hardware sensor on your machine that’s supported by lm-sensors for it to work, including the required kernel module. Fortunately this will often work out of the box.
After making sure you have sensors and that running ‘sensors’ will give output like this:
it8720-isa-0228
Adapter: ISA adapter
in0: +1.04 V (min = +0.00 V, max = +4.08 V)
in1: +1.66 V (min = +0.00 V, max = +4.08 V)
in2: +3.39 V (min = +0.00 V, max = +4.08 V)
+5V: +3.04 V (min = +0.00 V, max = +4.08 V)
in4: +3.10 V (min = +0.00 V, max = +4.08 V)
in5: +1.90 V (min = +0.00 V, max = +4.08 V)
in6: +4.08 V (min = +0.00 V, max = +4.08 V)
5VSB: +3.04 V (min = +0.00 V, max = +4.08 V)
Vbat: +3.30 V
fan1: 2235 RPM (min = 10 RPM)
fan2: 0 RPM (min = 0 RPM)
fan3: 2500 RPM (min = 0 RPM)
fan5: 0 RPM (min = 0 RPM)
temp1: +41.0°C (low = +127.0°C, high = +127.0°C) sensor = thermistor
temp2: +36.0°C (low = +127.0°C, high = +90.0°C) sensor = thermal diode
temp3: +38.0°C (low = +127.0°C, high = +127.0°C) sensor = thermistor
cpu0_vid: +1.250 V
k10temp-pci-00c3
Adapter: PCI adapter
temp1: +32.0°C (high = +70.0°C)
You might see things like ‘in0′ instead of ‘CPU Voltage’. Don’t ask me what voltage corresponds with what sensor on your mainboard, but you can rename the sensor output by editing /etc/sensors.conf or /etc/sensors3.conf depending on your flavor of linux.
In order for the check_mk plugin templates to recognize the type you’ll need to make sure they have some kind of indication of the type of sensor. For instance label the temperature sensors with ‘temp’ or ‘temperature’. The default names like ‘in0′ will also work, but something like ‘Pizza sensor’ obviously won’t.
To change labels or ignore certain sensors because they give bogus data (not connected etc), first find your adapter type.
In the example above this is it8720-isa-0228. Now edit the sensors.conf file and add a section
for this adapter if it isn’t already there.
Here’s an example for renaming in0 to “CPU Voltage” and turning off the second fan since it’s not connected.
Also we’ll change the minimum and maximum voltage for the CPU Voltage — this determines when nagios will send out an alarm or not:
set in0_min 1.0
set in0_max 2.0
label in0 "CPU Voltage"
ignore fan2
After changing the sensors file you’ll need to make lmsensors aware of the configuration change by running ‘sensors -s’. (might need root).
benv@localhost:~$ sensors
it8720-isa-0228
Adapter: ISA adapter
CPU Voltage: +1.31 V (min = +1.00 V, max = +2.00 V)
fan1: 2235 RPM (min = 10 RPM)
fan3: 2500 RPM (min = 0 RPM)
# some stuff deleted to save space :)
Tada. Now repeat this process for all sensors
Installation:
There are two parts to installing a Check MK plugin. First on the host that actually runs check_mk we need to install the package. This is quickly done:
root@checkmk# md5sum lmsensors-1.4.mkp
115bd50557d1db7e934baa64e172e506 lmsensors-1.4.mkp
root@checmk# check_mk -vP install lmsensors-1.4.mkp
Installing lmsensors version 1.4.
Checks:
lmsensors
Checks man pages:
lmsensors
Agents:
lmsensors
Multisite extensions:
plugins/perfometer/lmsensors.py
PNP4Nagios templates:
check_mk-lmsensors.php
check_mk-lmsensors.fan.php
check_mk-lmsensors.temp.php
check_mk-lmsensors.volt.php
root@checkmk# check_mk -II
lmsensors.fan 2 new checks
lmsensors.volt 4 new checks
root@checkmk# check_mk -O
Done. Soon there will be pretty graphs for this machine
Now for a remote machine you will need to put the agent in place. Since this is only a single file it’s trivial to do:
Note that the place you want to put that thing in is the $MK_LIBDIR/plugins directory. In my case, this was /usr/lib/check_mk_agent/plugins, but it could very well be somewhere else on your system. You can find it in the check_mk_agent script if you don’t know:
export MK_LIBDIR="/usr/lib/check_mk_agent"
PLUGINSDIR=$MK_LIBDIR/plugins
Let Check_MK do an inventory on your remote machine [check_mk -II $machine] and the rest goes automagically!
And now we have pretty graphs for my sensors.
Comments and/or suggestions are welcome.
Updates:
Version 1.1: now has pnp templates to put graphs of the same type together.
Here’s an example:
Version 1.2: changed sed to perl in agent plugin, sensornames with more than one space (among things) were giving issues. Thanks to Cyril Pawelko for finding the issue and helping with testing!
Version 1.3: minor change to PNP templates — Nico Weinreich informed me that his fan templates weren’t working correctly so I updated the regular expression used to match corresponding sensor types. If you didn’t have this issue this update won’t do anything useful for you
Version 1.4: Seems like I was a dumbass and didn’t check the 1.2 package properly. This package really makes it work with perl instead of sed.
Also updated the voltage pnp template to hopefully match more voltage sensors.
Note: if the pnp4nagios template doesn’t work for you, check your pnp4nagios perfdata dir, for example /var/lib/pnp4nagios/perfdata/ and see what .rrd files exist for your host. They are based on the sensor name, so if your sensor name is “St John”, it will not match the voltage template. These names come directly from your sensors.conf (if you don’t have it the default names for the sensors).
See above on how to rename your sensors.
Version 1.5: Another bug spotted by Cyril! The pnp4nagios temperature template had a botched variable name.
Downloads:
Check_MK Plugin: lmsensors - Version 1.5 - SHA: e2fc8efa037e041258315a7b0084e762eb71fae4
Check_MK Plugin: lmsensors - Version 1.4 - SHA: ba7837cb5f3efaf18e15c716715b34b07efacbf7
Check_MK Plugin: lmsensors - Version 1.3 - SHA: 6cb8489b98cfad11611266ef30519e4c1969a819
Check_MK Plugin: lmsensors - Version 1.2 - SHA: 5561268e13b890d66d7eda475b40716c98fd9543
Check_MK Plugin: lmsensors - Version 1.1 - SHA: 0738e0fd0a01cfcaaca5b9cb8fd1ada3d4a9c01e
Check_MK Plugin: lmsensors - Version 1.0 - SHA: 9454e00fa05aa39c49e7fc87d1a4855d68e4495f



September 28th, 2011 on 22:56
The bar graphs on the right side are not working for me. I just get “invalid data: global name ‘savefloat’ is not defined”
I am running OMD on Ubuntu 10.04 LTS with check_mk version 1.1.9i8
-Daniel
October 1st, 2011 on 15:19
danielbair: I guess your version of check_mk doesn’t include the definition of saveint/savefloat yet. If upgrading to a newer version isn’t an option you could try to remove the savefloat function in perfometer/lmsensors.py (lines 9 and 10), it should still work if the check reports good values.
November 22nd, 2011 on 10:46
Installation on check_mk Linux server has been successful (following your instructions)
“check_mk -II localhost” doesn’t reports any lmsensors data.
November 22nd, 2011 on 13:12
loreto: can you post/mail me the output of ‘sensors’ and ‘check_mk –debug –checks=lmsensors.temp -II localhost’ (if you think the temperature sensors should report something, otherwise ‘lmsensors.fan’ or ‘lmsensors.volt’)?
November 23rd, 2011 on 09:36
Ciao BenV, I didn’t find you email so I’m posting the output.
————————————————
- host588 – Check_mk server – Virtual Machine
————————————————
[root@host588]# check_mk -vP install /root/Check_MK/Plugins/lmsensors-1.0.mkp
Installing lmsensors version 1.0.
Checks:
lmsensors
Agents:
lmsensors
Multisite extensions:
plugins/perfometer/lmsensors.py
[root@host588]# check_mk -II localhost
cpu.loads 1 new checks
cpu.threads 1 new checks
df 8 new checks
diskstat 1 new checks
kernel 3 new checks
kernel.util 1 new checks
lnx_if 1 new checks
local 1 new checks
mem.used 1 new checks
ntp.time 1 new checks
postfix_mailq 1 new checks
tcp_conn_stats 1 new checks
uptime 1 new checks
*****
** lmsensors is not listed (may be it’s a VM)
*****
[root@host588]# check_mk -debug –checks=lmsensors.temp -II localhost
Network error: [Errno -2] Name or service not known
*****
** Now copying lmsensors to PM
*****
————————————-
- host755 – Physical machine
————————————-
root@host755# grep MK_LIBDIR $(which check_mk_agent)
export MK_LIBDIR=”/usr/lib/check_mk_agent”
PLUGINSDIR=$MK_LIBDIR/plugins
LOCALDIR=$MK_LIBDIR/local
*****
** Because of it didn’t work, I copied lmsensors on all check_mk directories
*****
scp -p /usr/share/check_mk/agents/lmsensors root@host755:/usr/lib/check_mk_agent/
scp -p /usr/share/check_mk/agents/lmsensors root@host755:/usr/lib/check_mk_agent/plugins/
scp -p /usr/share/check_mk/agents/lmsensors root@host755:/usr/lib/check_mk_agent/local/
scp -p /usr/share/check_mk/agents/lmsensors root@host755:/usr/share/check_mk/agents/
chmod 755 lmsensors
[root@host588]# check_mk -II host755
cpu.loads 1 new checks
cpu.threads 1 new checks
df 8 new checks
diskstat 1 new checks
kernel 3 new checks
kernel.util 1 new checks
mem.used 1 new checks
ntp.time 1 new checks
tcp_conn_stats 1 new checks
uptime 1 new checks
*****
** lmsensors is not listed
*****
[root@host588]# check_mk -debug –checks=lmsensors.temp -II host755
Network error: [Errno -2] Name or service not known
Ciao
November 23rd, 2011 on 11:07
My email is benv (at) junerules dot com
And you’re right: lmsensors doesn’t work on virtual machines, or at least, that’s my experience so far.
On the physical machine it should work however, depending on the sensors in your machine and whether or not they are supported by lmsensors (and in your kernel).
The check_mk lmsensors plugin expects ‘/usr/bin/sensors’ to exist and to provide output. For example, my server here at home outputs this:
benv@server:~$ sensors
lm85-i2c-0-2e
Adapter: SMBus I801 adapter at 2000
in0: +1.56 V (min = +0.00 V, max = +3.32 V)
Vcore: +1.34 V (min = +0.00 V, max = +2.99 V)
+3.3V: +3.33 V (min = +2.97 V, max = +3.63 V)
+5V: +5.10 V (min = +4.50 V, max = +5.50 V)
+12V: +12.00 V (min = +0.00 V, max = +15.94 V)
fan1: 1361 RPM (min = 0 RPM)
fan3: 952 RPM (min = 0 RPM)
fan4: 1251 RPM (min = 0 RPM)
temp1: +63.0 C (low = +0.0 C, high = +75.0 C)
M/B Temp: +49.0 C (low = +0.0 C, high = +65.0 C)
temp3: +39.0 C (low = +0.0 C, high = +55.0 C)
cpu0_vid: +1.088 V
Can you check if you have the tool and post the output here, and/or email it to me?
November 23rd, 2011 on 15:02
Note that I just updated the package, this version also includes a PNP4Nagios template and a little man page for the check.
December 5th, 2011 on 12:51
Ciao BenV,
Sorry for the delay of my answer, but since the command “sensor” did not include any output on my machine, I tried to install the drivers of the manufacturer. Unfortunately, the “sensor” command still does not give any result. We are investigating.
Ciao
Loreto