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)
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] . " ");
}
}
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