/**
  * getTemps 
  * 
  * @access private
  * @return array the temps
  */
 private function getTemps()
 {
     // Time?
     if (!empty($this->settings['timer'])) {
         $t = new LinfoTimerStart('Temperature');
     }
     // Hold them here
     $return = array();
     // hddtemp?
     if (array_key_exists('hddtemp', (array) $this->settings['temps']) && !empty($this->settings['temps']['hddtemp'])) {
         try {
             // Initiate class
             $hddtemp = new GetHddTemp($this->settings);
             // Set mode, as in either daemon or syslog
             $hddtemp->setMode($this->settings['hddtemp']['mode']);
             // If we're daemon, save host and port
             if ($this->settings['hddtemp']['mode'] == 'daemon') {
                 $hddtemp->setAddress($this->settings['hddtemp']['address']['host'], $this->settings['hddtemp']['address']['port']);
             }
             // Result after working it
             $hddtemp_res = $hddtemp->work();
             // If it's an array, it worked
             if (is_array($hddtemp_res)) {
                 // Save result
                 $return = array_merge($return, $hddtemp_res);
             }
         } catch (GetHddTempException $e) {
             $this->error->add('hddtemp parser', $e->getMessage());
         }
     }
     // mbmon?
     if (array_key_exists('mbmon', (array) $this->settings['temps']) && !empty($this->settings['temps']['mbmon'])) {
         try {
             // Initiate class
             $mbmon = new GetMbMon();
             // Set host and port
             $mbmon->setAddress($this->settings['mbmon']['address']['host'], $this->settings['mbmon']['address']['port']);
             // Get result after working it
             $mbmon_res = $mbmon->work();
             // If it's an array, it worked
             if (is_array($mbmon_res)) {
                 // Save result
                 $return = array_merge($return, $mbmon_res);
             }
         } catch (GetMbMonException $e) {
             $this->error->add('mbmon parser', $e->getMessage());
         }
     }
     // sensord? (part of lm-sensors)
     if (array_key_exists('sensord', (array) $this->settings['temps']) && !empty($this->settings['temps']['sensord'])) {
         try {
             // Iniatate class
             $sensord = new GetSensord();
             // Work it
             $sensord_res = $sensord->work();
             // If it's an array, it worked
             if (is_array($sensord_res)) {
                 // Save result
                 $return = array_merge($return, $sensord_res);
             }
         } catch (GetSensordException $e) {
             $this->error->add('sensord parser', $e->getMessage());
         }
     }
     // hwmon? (probably the fastest of what's here)
     // too simple to be in its own class
     if (array_key_exists('hwmon', (array) $this->settings['temps']) && !empty($this->settings['temps']['hwmon'])) {
         // Store them here
         $hwmon_vals = array();
         // Wacky location
         $hwmon_paths = (array) @glob('/sys/class/hwmon/hwmon*/*_label', GLOB_NOSORT);
         $num_paths = count($hwmon_paths);
         for ($i = 0; $i < $num_paths; $i++) {
             // The path
             $path = $hwmon_paths[$i];
             // Get info here
             $section = rtrim($path, 'label');
             $filename = basename($path);
             $label = getContents($path);
             $value = getContents($section . 'input');
             // Determine units and possibly fix values
             if (strpos($filename, 'fan') !== false) {
                 $unit = 'RPM';
             } elseif (strpos($filename, 'temp') !== false) {
                 $unit = 'C';
                 // Always seems to be in celsius
                 $value = strlen($value) == 5 ? substr($value, 0, 2) : $value;
                 // Pointless extra 0's
             } elseif (preg_match('/^in\\d_label$/', $filename)) {
                 $unit = 'v';
             } else {
                 $unit = '';
             }
             // Not sure if there's a temp
             // Append values
             $hwmon_vals[] = array('path' => 'N/A', 'name' => $label, 'temp' => $value, 'unit' => $unit);
         }
         // Save any if we have any
         if (count($hwmon_vals) > 0) {
             $return = array_merge($return, $hwmon_vals);
         }
     }
     // Additional weird bullshit? In this case, laptop backlight percentage. lolwtf, right?
     foreach ((array) @glob('/sys/{devices/virtual,class}/backlight/*/max_brightness', GLOB_NOSORT | GLOB_BRACE) as $bl) {
         $dir = dirname($bl);
         if (!is_file($dir . '/actual_brightness')) {
             continue;
         }
         $max = get_int_from_file($bl);
         $cur = get_int_from_file($dir . '/actual_brightness');
         if ($max < 0 || $cur < 0) {
             continue;
         }
         $return[] = array('name' => 'Backlight brightness', 'temp' => round($cur / $max, 2) * 100, 'unit' => '%', 'path' => 'N/A', 'bar' => true);
     }
     // Done
     return $return;
 }
示例#2
0
 /**
  * getTemps 
  * 
  * @access private
  * @return array the temps
  */
 public function getTemps()
 {
     // Time?
     if (!empty($this->settings['timer'])) {
         $t = new LinfoTimerStart('Temperature');
     }
     // Hold them here
     $return = array();
     // hddtemp?
     if (array_key_exists('hddtemp', (array) $this->settings['temps']) && !empty($this->settings['temps']['hddtemp']) && isset($this->settings['hddtemp'])) {
         try {
             // Initiate class
             $hddtemp = new GetHddTemp($this->settings);
             // Set mode, as in either daemon or syslog
             $hddtemp->setMode($this->settings['hddtemp']['mode']);
             // If we're daemon, save host and port
             if ($this->settings['hddtemp']['mode'] == 'daemon') {
                 $hddtemp->setAddress($this->settings['hddtemp']['address']['host'], $this->settings['hddtemp']['address']['port']);
             }
             // Result after working it
             $hddtemp_res = $hddtemp->work();
             // If it's an array, it worked
             if (is_array($hddtemp_res)) {
                 // Save result
                 $return = array_merge($return, $hddtemp_res);
             }
         } catch (GetHddTempException $e) {
             $this->error->add('hddtemp parser', $e->getMessage());
         }
     }
     // mbmon?
     if (array_key_exists('mbmon', (array) $this->settings['temps']) && !empty($this->settings['temps']['mbmon']) && isset($this->settings['mbmon'])) {
         try {
             // Initiate class
             $mbmon = new GetMbMon();
             // Set host and port
             $mbmon->setAddress($this->settings['mbmon']['address']['host'], $this->settings['mbmon']['address']['port']);
             // Get result after working it
             $mbmon_res = $mbmon->work();
             // If it's an array, it worked
             if (is_array($mbmon_res)) {
                 // Save result
                 $return = array_merge($return, $mbmon_res);
             }
         } catch (GetMbMonException $e) {
             $this->error->add('mbmon parser', $e->getMessage());
         }
     }
     // sensord? (part of lm-sensors)
     if (array_key_exists('sensord', (array) $this->settings['temps']) && !empty($this->settings['temps']['sensord'])) {
         try {
             // Iniatate class
             $sensord = new GetSensord();
             // Work it
             $sensord_res = $sensord->work();
             // If it's an array, it worked
             if (is_array($sensord_res)) {
                 // Save result
                 $return = array_merge($return, $sensord_res);
             }
         } catch (GetSensordException $e) {
             $this->error->add('sensord parser', $e->getMessage());
         }
     }
     // hwmon? (probably the fastest of what's here)
     // too simple to be in its own class
     if (array_key_exists('hwmon', (array) $this->settings['temps']) && !empty($this->settings['temps']['hwmon'])) {
         // Store them here
         $hwmon_vals = array();
         // Wacky location
         foreach ((array) @glob('/sys/class/hwmon/hwmon*/{,device/}*_input', GLOB_NOSORT | GLOB_BRACE) as $path) {
             $initpath = rtrim($path, 'input');
             $value = LinfoCommon::getContents($path);
             $base = basename($path);
             $labelpath = $initpath . 'label';
             $showemptyfans = isset($this->settings['temps_show0rpmfans']) ? $this->settings['temps_show0rpmfans'] : false;
             $drivername = @basename(@readlink(dirname($path) . '/driver')) ?: false;
             // Temperatures
             if (is_file($labelpath) && strpos($base, 'temp') === 0) {
                 $label = LinfoCommon::getContents($labelpath);
                 $value /= $value > 10000 ? 1000 : 1;
                 $unit = 'C';
                 // I don't think this is ever going to be in F
             } elseif (preg_match('/^fan(\\d+)_/', $base, $m)) {
                 $label = 'fan' . $m[1];
                 $unit = 'RPM';
                 if ($value == 0 && !$showemptyfans) {
                     continue;
                 }
             } elseif (preg_match('/^in(\\d+)_/', $base, $m)) {
                 $unit = 'V';
                 $value /= 1000;
                 $label = LinfoCommon::getContents($labelpath) ?: 'in' . $m[1];
             } else {
                 continue;
             }
             // Append values
             $hwmon_vals[] = array('path' => '', 'name' => $label . ($drivername ? ' <span class="faded">(' . $drivername . ')</span>' : ''), 'temp' => $value, 'unit' => $unit);
         }
         // Save any if we have any
         if (count($hwmon_vals) > 0) {
             $return = array_merge($return, $hwmon_vals);
         }
     }
     // Laptop backlight percentage
     foreach ((array) @glob('/sys/{devices/virtual,class}/backlight/*/max_brightness', GLOB_NOSORT | GLOB_BRACE) as $bl) {
         $dir = dirname($bl);
         if (!is_file($dir . '/actual_brightness')) {
             continue;
         }
         $max = LinfoCommon::getIntFromFile($bl);
         $cur = LinfoCommon::getIntFromFile($dir . '/actual_brightness');
         if ($max < 0 || $cur < 0) {
             continue;
         }
         $return[] = array('name' => 'Backlight brightness', 'temp' => round($cur / $max, 2) * 100, 'unit' => '%', 'path' => 'N/A', 'bar' => true);
     }
     // Done
     return $return;
 }