Page 1 of 1

cpu temperature with sensors

Posted: Wed Sep 26, 2007 5:30 pm
by aleppax
I've added the monitoring of the cpu temp using sensors and a simple php function. Here is the code (sensors must be installed and configured; the content of the function is a first attempt tested only on my box):

zm_funcs.php (add this function:)

Code: Select all

function getTemperature()
{
        $te = shell_exec( 'sensors' );
        $tem = explode("temp2:",$te);
	$tempe = explode("C",$tem[1]);
	return( $tempe[0] );
}
zm_html_view_console.php (line 226 becomes:)

Code: Select all

<td class="smallhead" align="right"><?= $zmSlangLoad ?>: <?= getLoad() ?> / <?= $zmSlangDisk ?>: <?= getDiskPercent() ?>% / <?= getTemperature() ?>&deg;C</td>
the function can be easily adapted to monitor also the motherboard temperature.

Image

Posted: Thu Sep 27, 2007 5:28 pm
by Lee Sharp
That could be handy. I have had many systems die from a sudden change in environmental heat. It would be nice to know.

Posted: Thu Oct 04, 2007 4:08 pm
by qriff
Great, other option would be to combine/embed/run Munin graphs with Zoneminder.

http://munin.projects.linpro.no

Live demo: http://munin.ping.uio.no/

Re: cpu temperature with sensors

Posted: Wed Dec 19, 2007 10:41 pm
by robi
aleppax wrote:I've added the monitoring of the cpu temp using sensors and a simple php function. Here is the code (sensors must be installed and configured; the content of the function is a first attempt tested only on my box):
Many thanks, it works great! 8)

Posted: Thu Dec 20, 2007 1:02 pm
by robi
Just to clarify for the people, before someone says it's not working.

sensors outputs something like this, depending on the motherboard and settings:
it8712-isa-0290 Adapter: ISA adapter VCore 1: +1.52 V (min = +1.42 V, max = +1.57 V) VCore 2: +2.54 V (min = +2.40 V, max = +2.61 V) +3.3V: +3.23 V (min = +3.14 V, max = +3.47 V) +5V: +4.11 V (min = +4.76 V, max = +5.24 V) ALARM +12V: +12.29 V (min = +11.39 V, max = +12.61 V) -12V: -16.19 V (min = -12.63 V, max = -11.41 V) ALARM -5V: -8.17 V (min = -5.26 V, max = -4.77 V) ALARM Stdby: +3.95 V (min = +4.76 V, max = +5.24 V) ALARM VBat: +4.08 V M/B Temp1: +25 C (low = +15 C, high = +40 C) sensor = thermistor M/B Temp2: +26 C (low = +15 C, high = +45 C) sensor = thermistor CPU Temp: +34 C (low = +15 C, high = +65 C) sensor = diode
The line in bold is what we need, so for this example above, the code must be changed like this:

Code: Select all

function getTemperature() 
{ 
        $te = shell_exec( 'sensors' ); 
        $tem = explode("CPU Temp:",$te); 
   $tempe = explode("C",$tem[1]); 
   return( $tempe[0] ); 
}
So one has to find the words before the reported cpu temperature and replace them in the code above. lm_sensors configuration file offers a lot of nice things also.

Posted: Sat Dec 22, 2007 4:16 am
by linuxsense
Great idea...thanks for the code. I made a few small changes and have mine set to display both of my cpu cores. Sweet.

For those of you looking to add the temp display with ZM 1.23 look at or around line 269 to insert the temp display code in zm_html_view_console.php...at least as of RC3.

Posted: Sat Dec 29, 2007 4:34 pm
by robi
linuxsense wrote:to add the temp display with ZM 1.23 look at or around line 269 to insert the temp display code in zm_html_view_console.php
Yep, that's right there to be inserted. Works like a charm.

Actually I hate the + sign in front of the temp (it's obvoius that this is a positive temperature, dohh), so to remove

Code: Select all

function getTemperature()
{
        $te = shell_exec( 'sensors' );
        $tem = explode("CPU Temp:",$te);
   $tempe = explode("C",$tem[1]);
   return(str_replace("+","", $tempe[0]));
}

Code: Select all

 / Cpu:<?= getTemperature() ?>&deg;C

Posted: Mon Jul 20, 2009 2:22 pm
by robi
If you're using 1.24.x, then the mods are the following:

in the file
/var/www/zm/includes/functions.php
add this function:

Code: Select all

function getTemperature()
{
        $te = shell_exec( 'sensors' );
        $tem = explode("CPU:",$te);
   $tempe = explode("C",$tem[1]);
   return(str_replace(" ","", str_replace("+","", $tempe[0])));
}
(make sure to adjust code according to what your sensors outputs, see above)


in the file
/var/www/zm/skins/classic/views/console.php
search for:

Code: Select all

      <h3 id="systemStats"><?= $SLANG['Load'] ?>: <?= getLoad() ?> / <?= $SLANG['Disk'] ?>: <?= getDiskPercent() ?>%</h3>
and replace with:

Code: Select all

      <h3 id="systemStats"><?= $SLANG['Load'] ?>: <?= getLoad() ?> / <?= $SLANG['Disk'] ?>: <?= getDiskPercent() ?>% / Cpu: <?= getTemperature() ?>&deg;C</h3>