cpu temperature with sensors

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
aleppax
Posts: 3
Joined: Wed Sep 26, 2007 3:04 pm

cpu temperature with sensors

Post 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
User avatar
Lee Sharp
Posts: 1069
Joined: Sat Mar 31, 2007 9:18 pm
Location: Houston, TX

Post 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.
qriff
Posts: 15
Joined: Thu Sep 20, 2007 9:11 pm

Post 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/
User avatar
robi
Posts: 477
Joined: Sat Mar 17, 2007 10:48 am

Re: cpu temperature with sensors

Post 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)
v1.25.0 + Ubuntu Linux 12.04 Server
User avatar
robi
Posts: 477
Joined: Sat Mar 17, 2007 10:48 am

Post 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.
v1.25.0 + Ubuntu Linux 12.04 Server
linuxsense
Posts: 374
Joined: Wed Nov 07, 2007 1:59 am
Location: Huntington Beach, California
Contact:

Post 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.
User avatar
robi
Posts: 477
Joined: Sat Mar 17, 2007 10:48 am

Post 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
v1.25.0 + Ubuntu Linux 12.04 Server
User avatar
robi
Posts: 477
Joined: Sat Mar 17, 2007 10:48 am

Post 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>
v1.25.0 + Ubuntu Linux 12.04 Server
Post Reply