/** * 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); } } } }
private function _temperature() { $temp = file_get_contents('/sys/class/thermal/thermal_zone0/temp'); $temp_max = file_get_contents('/sys/class/thermal/thermal_zone0/trip_point_0_temp'); $temp = $temp / 1000; $temp_max = $temp_max / 1000; $dev = new SensorDevice(); $dev->setName("CPU " . 1); $dev->setValue($temp); $dev->setMax($temp_max); $this->mbinfo->setMbTemp($dev); }
/** * get fan information * * @return void */ private function _fans() { if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 127.0.0.1 .1.3.6.1.4.1.24681.1.2.15.1.3", $buffer, PSI_DEBUG)) { $lines = preg_split('/\\r?\\n/', $buffer); foreach ($lines as $line) { if (preg_match('/^[\\.\\d]+\\.(\\d+) = STRING:\\s\\"?(\\d+)\\sRPM/', $line, $data)) { $dev = new SensorDevice(); $dev->setName("Fan " . $data[1]); $dev->setValue($data[2]); $this->mbinfo->setMbFan($dev); } } } }
/** * get voltage information * * @return void */ private function _voltage() { foreach ($this->_lines as $line) { $buffer = preg_split("/[ ]+\\|[ ]+/", $line); if ($buffer[2] == "Volts" && $buffer[5] != "na") { $dev = new SensorDevice(); $dev->setName($buffer[0]); $dev->setValue($buffer[1]); $dev->setMin($buffer[5]); $dev->setMax($buffer[8]); $this->mbinfo->setMbVolt($dev); } } }
/** * get temperature information * * @return void */ private function _temperature() { $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)) { $dev = new SensorDevice(); $dev->setName("CPU " . ($i + 1)); $dev->setValue($temp); $dev->setMax(70); $this->mbinfo->setMbTemp($dev); } } }
/** * get temperature information * * @return void */ private function _temperature() { foreach ($this->_lines as $line) { if (preg_match('/(.*):\\s*(\\d*)/', $line, $data)) { if ($data[2] > 0) { $dev = new SensorDevice(); $dev->setName($data[1]); $dev->setMax('70.0'); if ($data[2] < 250) { $dev->setValue($data[2]); } $this->mbinfo->setMbTemp($dev); } } } }
/** * get current information * * @return void */ private function _current() { foreach ($this->_lines as $line) { $buffer = preg_split("/\\s*\\|\\s*/", $line); if (isset($buffer[2]) && $buffer[2] == "Current" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\\S+)\\sA\$/", $buffer[6], $value)) { $dev = new SensorDevice(); $dev->setName($buffer[4]); $dev->setValue($value[1]); if (isset($buffer[7]) && $buffer[7] == "Thresholds") { if (isset($buffer[8]) && preg_match("/^hi-crit\\s(\\S+)\\s*\$/", $buffer[8], $limits) || isset($buffer[9]) && preg_match("/^hi-crit\\s(\\S+)\\s*\$/", $buffer[9], $limits) || isset($buffer[10]) && preg_match("/^hi-crit\\s(\\S+)\\s*\$/", $buffer[10], $limits) || isset($buffer[11]) && preg_match("/^hi-crit\\s(\\S+)\\s*\$/", $buffer[11], $limits)) { $dev->setMax($limits[1]); } } if ($buffer[5] != "OK") { $dev->setEvent($buffer[5]); } $this->mbinfo->setMbCurrent($dev); } } }
/** * get voltage information * * @return array voltage in array with lable */ private function _voltage() { $ar_buf = preg_split("/\t+/", $this->_lines); $dev1 = new SensorDevice(); $dev1->setName('Vcore1'); $dev1->setValue($ar_buf[7]); $this->mbinfo->setMbVolt($dev1); $dev2 = new SensorDevice(); $dev2->setName('Vcore2'); $dev2->setValue($ar_buf[8]); $this->mbinfo->setMbVolt($dev2); $dev3 = new SensorDevice(); $dev3->setName('3volt'); $dev3->setValue($ar_buf[9]); $this->mbinfo->setMbVolt($dev3); $dev4 = new SensorDevice(); $dev4->setName('+5Volt'); $dev4->setValue($ar_buf[10]); $this->mbinfo->setMbVolt($dev4); $dev5 = new SensorDevice(); $dev5->setName('+12Volt'); $dev5->setValue($ar_buf[11]); $this->mbinfo->setMbVolt($dev5); $dev6 = new SensorDevice(); $dev6->setName('-12Volt'); $dev6->setValue($ar_buf[12]); $this->mbinfo->setMbVolt($dev6); $dev7 = new SensorDevice(); $dev7->setName('-5Volt'); $dev7->setValue($ar_buf[13]); $this->mbinfo->setMbVolt($dev7); }
/** * get voltage information * * @return void */ private function _voltage() { foreach ($this->_lines as $line) { $ar_buf = preg_split("/[\\s,]+/", $line); if (isset($ar_buf[3]) && $ar_buf[2] == 'volts_dc') { $dev = new SensorDevice(); $dev->setName($ar_buf[1]); $dev->setValue($ar_buf[3]); $this->mbinfo->setMbVolt($dev); } } }
/** * get current information * * @return void */ private function _current($hwpath) { $sensor = glob($hwpath . "curr*_input", GLOB_NOSORT); if (($total = count($sensor)) > 0) { $buf = ""; for ($i = 0; $i < $total; $i++) { if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && trim($buf) != "") { $dev = new SensorDevice(); $dev->setValue(trim($buf) / 1000); $label = preg_replace("/_input\$/", "_label", $sensor[$i]); $alarm = preg_replace("/_input\$/", "_alarm", $sensor[$i]); $max = preg_replace("/_input\$/", "_max", $sensor[$i]); $min = preg_replace("/_input\$/", "_min", $sensor[$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($sensor[$i], PATHINFO_BASENAME))); if ($labelname !== "") { $dev->setName($labelname); } else { $dev->setName('unknown'); } } if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setMax(trim($buf) / 1000); } if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && trim($buf) != "") { $dev->setMin(trim($buf) / 1000); } if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && trim($buf) === "1") { $dev->setEvent("Alarm"); } $this->mbinfo->setMbCurrent($dev); } } } }
/** * get voltage information * * @return void */ private function _voltage() { foreach ($this->_lines as $line) { if (preg_match('/^(V.*)\\s*:\\s*(.*)$/D', $line, $data)) { if ($data[2] != '+0.00') { $dev = new SensorDevice(); $dev->setName($data[1]); $dev->setValue($data[2]); $this->mbinfo->setMbVolt($dev); } } } }
/** * get current information * * @return void */ private function _current() { foreach ($this->_lines as $line) { $buffer = preg_split("/\\s*\\|\\s*/", $line); if ($buffer[2] == "Amps" && $buffer[3] != "na") { $dev = new SensorDevice(); $dev->setName($buffer[0]); $dev->setValue($buffer[1]); if ($buffer[8] != "na") { $dev->setMax($buffer[8]); } $this->mbinfo->setMbCurrent($dev); } } }
/** * get voltage information * * @return void */ private function _voltage() { foreach ($this->_lines as $line) { if (preg_match('/^hw\\.sensors\\.[0-9]+=[^\\s,]+,\\s+([^,]+),\\s+volts_dc,\\s+([0-9\\.]+)\\s+V.*$/', $line, $ar_buf)) { $dev = new SensorDevice(); $dev->setName($ar_buf[1]); $dev->setValue($ar_buf[2]); $this->mbinfo->setMbVolt($dev); } elseif (preg_match('/^hw\\.sensors\\.[0-9]+=[^\\s,]+,\\s+([^,]+),\\s+([0-9\\.]+)\\s+V\\sDC$/', $line, $ar_buf)) { $dev = new SensorDevice(); $dev->setName($ar_buf[1]); $dev->setValue($ar_buf[2]); $this->mbinfo->setMbVolt($dev); } elseif (preg_match('/^hw\\.sensors\\.[^\\.]+\\.(.*)=([0-9\\.]+)\\s+VDC\\s+\\((.*)\\)$/', $line, $ar_buf)) { $dev = new SensorDevice(); $dev->setName($ar_buf[3]); $dev->setValue($ar_buf[2]); $this->mbinfo->setMbVolt($dev); } elseif (preg_match('/^hw\\.sensors\\.[^\\.]+\\.(.*)=([0-9\\.]+)\\s+VDC$/', $line, $ar_buf)) { $dev = new SensorDevice(); $dev->setName($ar_buf[1]); $dev->setValue($ar_buf[2]); $this->mbinfo->setMbVolt($dev); } } }
/** * get current information * * @return void */ private function _current() { foreach ($this->_lines as $line) { $buffer = preg_split("/\\s*\\|\\s*/", $line); if ($buffer[2] == "Current" && $buffer[11] != "N/A" && $buffer[4] == "A") { $dev = new SensorDevice(); $dev->setName($buffer[1]); $dev->setValue($buffer[3]); if ($buffer[9] != "N/A") { $dev->setMax($buffer[9]); } if ($buffer[11] != "'OK'") { $dev->setEvent(trim($buffer[11], "'")); } $this->mbinfo->setMbCurrent($dev); } } }
/** * get fan information * * @return void */ private function _fans() { foreach ($this->_lines as $line) { $buffer = preg_split("/[ ]+\\|[ ]+/", $line); if ($buffer[2] == "RPM" && $buffer[3] != "na") { $dev = new SensorDevice(); $dev->setName($buffer[0]); $dev->setValue($buffer[1]); $dev->setMin($buffer[8]); $this->mbinfo->setMbFan($dev); } } }
/** * get current information * * @return void */ private function _current() { foreach ($this->_lines as $line) { $buffer = preg_split("/\\s*\\|\\s*/", $line); if ($buffer[2] == "Amps" && $buffer[3] != "na") { $dev = new SensorDevice(); $dev->setName($buffer[0]); $dev->setValue($buffer[1]); if ($buffer[8] != "na") { $dev->setMax($buffer[8]); } /* incorrect events recognition switch ($buffer[3]) { case "nr": $dev->setEvent("Non-Recoverable"); break; case "cr": $dev->setEvent("Critical"); break; case "nc": $dev->setEvent("Non-Critical"); break; } */ $this->mbinfo->setMbCurrent($dev); } } }
/** * get power information * * @return void */ private function _power() { if ($this->_buf) { foreach ($this->_buf as $buffer) { if ($buffer['SensorType'] == "Power") { $dev = new SensorDevice(); $dev->setName($buffer['Parent'] . ' ' . $buffer['Name']); $dev->setValue($buffer['Value']); $this->mbinfo->setMbPower($dev); } } } }
/** * get the temperature information from hddtemp * access is available through tcp or command * * @return array temperatures in array */ private function _temperature() { $ar_buf = array(); switch (strtolower(PSI_HDD_TEMP)) { case "tcp": $lines = ''; // Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout. $fp = @fsockopen('localhost', 7634, $errno, $errstr, 5); // if connected, read the output of the hddtemp daemon if ($fp) { while (!feof($fp)) { $lines .= fread($fp, 1024); } fclose($fp); } else { $this->error->addError("HDDTemp error", $errno . ", " . $errstr); } $lines = str_replace("||", "|\n|", $lines); $ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY); break; case "command": $strDrives = ""; $strContent = ""; $hddtemp_value = ""; if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) { $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY); foreach ($arrContent as $strLine) { preg_match("/^\\s(.*)\\s([a-z]*)\\s(.*)/", $strLine, $arrSplit); if (!empty($arrSplit[2])) { $strDrive = '/dev/' . $arrSplit[2]; if (file_exists($strDrive)) { $strDrives = $strDrives . $strDrive . ' '; } } } } else { if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) { $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY); foreach ($arrContent as $strLine) { if (!preg_match("/^\\s(.*)\\s([\\/a-z0-9]*(\\/disc))\\s(.*)/", $strLine, $arrSplit)) { preg_match("/^\\s(.*)\\s([a-z]*)\\s(.*)/", $strLine, $arrSplit); } if (!empty($arrSplit[2])) { $strDrive = '/dev/' . $arrSplit[2]; if (file_exists($strDrive)) { $strDrives = $strDrives . $strDrive . ' '; } } } } } if (trim($strDrives) == "") { break; } if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, PSI_DEBUG)) { $hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY); foreach ($hddtemp_value as $line) { $temp = preg_split("/:\\s/", $line, 3); if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) { preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp); $temp[2] = trim($ar_temp[1]); $temp[3] = trim($ar_temp[2]); array_push($ar_buf, "|" . implode("|", $temp) . "|"); } } } break; default: $this->error->addConfigError("temperature()", "PSI_HDD_TEMP"); break; } // Timo van Roermund: parse the info from the hddtemp daemon. foreach ($ar_buf as $line) { $data = array(); if (preg_match("/\\|(.*)\\|(.*)\\|(.*)\\|(.*)\\|/", $line, $data)) { if (trim($data[3]) != "ERR") { // get the info we need $dev = new SensorDevice(); $dev->setName($data[1] . ' (' . (strpos($data[2], " ") ? substr($data[2], 0, strpos($data[2], " ")) : $data[2]) . ')'); if (is_numeric($data[3])) { $dev->setValue($data[3]); } $dev->setMax(60); $this->mbinfo->setMbTemp($dev); } } } }
/** * get temperature information * * @return void */ private function _temperature() { if (PSI_OS == 'WINNT') { if ($this->_buf) { foreach ($this->_buf as $buffer) { if (isset($buffer['CurrentTemperature']) && ($value = ($buffer['CurrentTemperature'] - 2732) / 10) > -100) { $dev = new SensorDevice(); if (isset($buffer['InstanceName']) && preg_match("/([^\\\\ ]+)\$/", $buffer['InstanceName'], $outbuf)) { $dev->setName('ThermalZone ' . $outbuf[1]); } else { $dev->setName('ThermalZone THM0_0'); } $dev->setValue($value); if (isset($buffer['CriticalTripPoint']) && ($maxvalue = ($buffer['CriticalTripPoint'] - 2732) / 10) > 0) { $dev->setMax($maxvalue); } $this->mbinfo->setMbTemp($dev); } } } } else { $notwas = true; foreach (glob('/sys/class/thermal/thermal_zone*/') as $thermalzone) { $thermalzonetemp = $thermalzone . 'temp'; $temp = null; if (CommonFunctions::rfts($thermalzonetemp, $temp, 0, 4096, false) && !is_null($temp) && trim($temp) != "") { if ($temp >= 1000) { $temp = $temp / 1000; } elseif ($temp >= 200) { $temp = $temp / 10; } if ($temp > -40) { $dev = new SensorDevice(); $dev->setValue($temp); $temp_type = null; if (CommonFunctions::rfts($thermalzone . 'type', $temp_type, 0, 4096, false) && !is_null($temp_type) && trim($temp_type) != "") { $dev->setName($temp_type); } else { $dev->setName("ThermalZone"); } $temp_max = null; if (CommonFunctions::rfts($thermalzone . 'trip_point_0_temp', $temp_max, 0, 4096, false) && !is_null($temp_max) && trim($temp_max) != "" && $temp_max > -40) { if ($temp_max >= 1000) { $temp_max = $temp_max / 1000; } elseif ($temp_max >= 200) { $temp_max = $temp_max / 10; } $dev->setMax($temp_max); } $notwas = false; $this->mbinfo->setMbTemp($dev); } } } if ($notwas) { foreach (glob('/proc/acpi/thermal_zone/TH*/temperature') as $thermalzone) { $temp = null; if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && !is_null($temp) && trim($temp) != "") { $dev = new SensorDevice(); if (preg_match("/^\\/proc\\/acpi\\/thermal_zone\\/(.+)\\/temperature\$/", $thermalzone, $name)) { $dev->setName("ThermalZone " . $name[1]); } else { $dev->setName("ThermalZone"); } $dev->setValue(trim(substr($temp, 23, 4))); $this->mbinfo->setMbTemp($dev); } } } } }
/** * get voltage information * * @return void */ private function _voltage() { if (isset($this->_filecontent["volt"]) && trim($this->_filecontent["volt"]) !== "") { $values = preg_split("/ /", trim($this->_filecontent["volt"])); foreach ($values as $id => $value) { $dev = new SensorDevice(); $dev->setName("in" . $id); $dev->setValue($value); $this->mbinfo->setMbVolt($dev); } } }
/** * get voltage information * * @return void */ private function _voltage() { for ($intPosi = 6; $intPosi < 13; $intPosi++) { if ($this->_buf_value[$intPosi] == 0) { continue; } preg_match("/([0-9\\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits); $dev = new SensorDevice(); $dev->setName($this->_buf_label[$intPosi]); $dev->setValue($hits[0]); $this->mbinfo->setMbVolt($dev); } }
/** * get current information * * @return void */ private function _current() { $ar_buf = array(); foreach ($this->_lines as $line) { $data = array(); if (preg_match("/(.*):(.*)\\((.*)=(.*),(.*)=(.*)\\)(.*)/", $line, $data)) { } elseif (preg_match("/(.*):(.*)\\((.*)=(.*)\\)(.*)/", $line, $data)) { } else { preg_match("/(.*):(.*)/", $line, $data); } if (count($data) > 1) { $temp = substr(trim($data[2]), -2); switch ($temp) { case " A": array_push($ar_buf, $line); } } } foreach ($ar_buf as $line) { $data = array(); /* not tested yet if (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A,(.*)=(.*) A\)(.*)\)/", $line, $data)) { ; } elseif (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A,(.*)=(.*) A\)(.*)/", $line, $data)) { ; } else */ if (preg_match("/(.*):(.*) A[ ]*\\((.*)=(.*) A\\)(.*)/", $line, $data)) { } elseif (preg_match("/(.*):(.*) A[ \t]+/", $line, $data)) { } else { preg_match("/(.*):(.*) A\$/", $line, $data); } foreach ($data as $key => $value) { if (preg_match("/^\\+?([0-9\\.]+).?\$/", trim($value), $newvalue)) { $data[$key] = trim($newvalue[1]); } else { $data[$key] = trim($value); } } $dev = new SensorDevice(); $dev->setName($data[1]); $dev->setValue($data[2]); if (isset($data[6]) && $data[2] <= $data[6]) { $dev->setMax(max($data[4], $data[6])); } elseif (isset($data[4]) && $data[2] <= $data[4]) { $dev->setMax($data[4]); } if (preg_match("/\\sALARM(\\s*)\$/", $line)) { $dev->setEvent("Alarm"); } $this->mbinfo->setMbCurrent($dev); } }
private function _current() { $current = null; if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/current_now', $current, 0, 4096, false) && !is_null($current) && trim($current) != "") { // Banana Pi $dev = new SensorDevice(); $dev->setName("Current 1"); $dev->setValue($current / 1000000); $this->mbinfo->setMbCurrent($dev); } }