h1

Howto monit temperature with Monit/Mmonit (Cómo monitorizar temperatura con Monit/Mmonit)

04/07/2009

In this article i will develop a plugin for mmonit for monitoring the CPU temperature and send alerts (emails) if it detects problems. Althought it seems to have a lot of steps, in 3 minutes you can get it up and running:

1º) Install the Linux package temperature.
After this, running “sensors” will show the temperature:

carlos@WhenIGrowUp:~$ sensors
k8temp-pci-00c3
Adapter: PCI adapter
Core0 Temp: -49.0°C
Core1 Temp: +56.0°C
M/B Temp: +55.0°C (low = -1.0°C, high = +127.0°C) sensor = thermistor
CPU Temp: +45.0°C (low = -1.0°C, high = +127.0°C) sensor = thermistor
Temp3: -128.0°C (low = -1.0°C, high = +127.0°C) sensor = disabled

2º) Download, check and install this script in your crontab.
This script will check the temperature, write it in the file /tmp/tempFile and, as Monit can’t read content of files, set the permissions as the following:

if temp is OK, /tmp/tempFile permissions will be 700
if it is a warning temp, /tmp/tempFile permissions will be 710
If it is a danger temp, /tmp/tempFile permissions will be 712

Later, Monit will check the permissions of this file, so it will know if the system is in trouble.

Run the script to test it:
carlos@shirley:~/hardware$ ./monit.temperature.sh
Temperature is: 45
Temp OK

Throubleshooting: if you get no result,
carlos@shirley:~/hardware$ ./monit.temperature.sh
Temperature is:
Temp OK
edit the script and change CPU with the name of the line with the info (delete “temp3” and write “CPU” i.e) where you can see the temperature runnning “sensors”:
carlos@shirley:~/hardware$ nano monit.temperature.sh
temp=$(sensors | grep temp3) <-- Replace temp3 with CPU or a string of the output "sensors".

Now, install it in your crontab to be executed every minute:
# crontab -e
* * * * * /home/carlos/monit.temperature.sh

3º) Install and run Monit (not Mmonit, his commercial brother). Monit is GNU. Here you can see a quick guide.
Monit is an utility for monitoring systems (HD, processes, resources, connectivity, networks…), sending alerts and taking actions . Install it:

# sudo apt-get install monit
(or download last version here)

4º) Add these lines to /etc/monit/monitrc
# sudo nano /etc/monit/monitrc
[...]
check file TemperatureOK with path /tmp/tempFile
if failed permission 700 then alert
check file warningTemperature with path /tmp/tempFile
if failed permission 710 then alert
check file dangerTemperature with path /tmp/tempFile
if failed permission 712 then alert
[...]

for checking the correct syntax of Monit’s control file, run:
# sudo monit -tc /etc/monit/monitrc
Control file syntax OK

And restart it
# sudo /etc/init.d/monit restart

5º) Check Monit’s web interface, you will get something like this:
http://172.26.0.1:2812 (default: admin // monit)
monit.temperature.example

Anuncios

2 comentarios

  1. Gracias! estaba tratando de hacer algo parecido… asignando lo permisos fue buena idea para resolver las limitaciones de monit.


  2. Hi there,

    Any chance of working link for the script from section 2?

    Many thanks



Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: