/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
if (PSI_OS == 'Linux') {
$hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
if (($totalh = count($hwpaths)) > 0) {
$buf = "";
for ($h = 0; $h < $totalh; $h++) {
$tempsensor = glob($hwpaths[$h] . "temp*_input", GLOB_NOSORT);
if (($total = count($tempsensor)) > 0) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($tempsensor[$i], $buf, 1, 4096, false) && trim($buf) != "") {
$dev = new SensorDevice();
$dev->setValue(trim($buf) / 1000);
$label = preg_replace("/_input\$/", "_label", $tempsensor[$i]);
$crit = preg_replace("/_input\$/", "_crit", $tempsensor[$i]);
$max = preg_replace("/_input\$/", "_max", $tempsensor[$i]);
$crit_alarm = preg_replace("/_input\$/", "_crit_alarm", $tempsensor[$i]);
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setName(trim($buf));
} else {
$labelname = trim(preg_replace("/_input\$/", "", pathinfo($tempsensor[$i], PATHINFO_BASENAME)));
if ($labelname !== "") {
$dev->setName($labelname);
} else {
$dev->setName('unknown');
}
}
if (CommonFunctions::fileexists($crit) && CommonFunctions::rfts($crit, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setMax(trim($buf) / 1000);
if (CommonFunctions::fileexists($crit_alarm) && CommonFunctions::rfts($crit_alarm, $buf, 1, 4096, false) && trim($buf) === "1") {
$dev->setEvent("Critical Alarm");
}
} elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setMax(trim($buf) / 1000);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
}
} else {
$smp = 1;
CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
for ($i = 0; $i < $smp; $i++) {
$temp = 0;
if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.' . $i . '.temperature', $temp)) {
$temp = preg_replace('/C/', '', $temp);
$dev = new SensorDevice();
$dev->setName("CPU " . ($i + 1));
$dev->setValue($temp);
// $dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
}
}