lm-sensors php script

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
ppost
Posts: 4
Joined: Sun Dec 21, 2014 1:11 pm

lm-sensors php script

Post by ppost »

Good day,

I need to write a .php script to get the temperature of "Core 0" from below console output:

Code: Select all

Server01> sensors                                 
coretemp-isa-0000                                       
Adapter: ISA adapter                                    
Core 0:       +40.0 C  (crit = +100.0 C)                
                                                        
coretemp-isa-0002                                       
Adapter: ISA adapter                                    
Core 2:       +40.0 C  (crit = +100.0 C)                
                                                        
it8720-isa-0a10                                         
Adapter: ISA adapter                                    
in0:          +2.88 V  (min =  +0.00 V, max =  +4.08 V) 
EDIT - I got the script sorted per below:

Code: Select all

$cmd= exec('sensors',$output);

foreach ($output as $line) 
{
	// need to find the temperature in:
	// Core 0:       +39.0 C  (crit = +100.0 C)
	if (preg_match('/Core\s+0:\s+\+(\d+).*/',$line,$match)) 
	{
		//print_r($match);
		print ("cpu_temperature:" . $match[1] . " ");
	}

	// need to find the temperature in:
	// temp1:        +49.0 C  (low  =  -1.0 C, high = +127.0 C)  sensor = thermistor 
	if (preg_match('/temp1:\s+\+(\d+).*/',$line,$match)) 
	{
		//print_r($match);
		print ("case_temperature:" . $match[1] . " ");
	}

}
BUT the graph does not show the right temperatures. I checked the script by running it in a console and the output conforms to the lm-sensors output. I checked each setting in the cacti template and all looks ok.

The results displayed in cacti are quite strange: from an actual core temperature of 39 degree C it displays values from 42 to 44. If the actual value is 40 cacti displays 43. This does not happen on any other graph in cact.

I have attached the script and template and would appreciate if someone could try it and help finding the mistake.

Thanks, brgds
Attachments
LM-Sensors_Cacti_Template_updated2.zip
(2.85 KiB) Downloaded 152 times
ppost
Posts: 4
Joined: Sun Dec 21, 2014 1:11 pm

Re: lm-sensors php script

Post by ppost »

For the record - I found that the Atom processor involved seems to be quite temperature sensitive when it comes to load increases. That means, the Cacti poller itself is driving the temperatures up just when reading it out. So it works correctly.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests