Newer
Older
<?php
namespace App\Sensor;
/**
* Description of Update
*
* @author helha
*/
class CPUtemperature extends \App\AbstractSensor
{
const REGEXP = "/^(Core \d+):\s+\+(\d+\.\d+)/m"; ///^(Core\s\d):\s+\/m
public function report()
{
$record = $this->getLastRecord("cpu-temperature");
return "<p>No data available...</p>"
. "<p>Maybe <code>sensors</code> is not installed.</p>"
. "<p>You can install it with <code>sudo apt install lm-sensors</code></p>";
$return = "<table class='table table-sm'>";
$return .= "<tr><th>Name</th><th>Temperature (°C)</th></tr>";
foreach ($temperatures as $temperature) {
$return .= "<tr><td>" . $temperature->name . "</td><td>"
. $temperature->value . "</td></tr>";
}
$return .= "</table>";
return $return;
}
public function status()
{
$record = $this->getLastRecord("cpu-temperature");
if ($record == null) {
return self::STATUS_UNKNOWN;
}
$all_status = [];
foreach (self::parse($record['cpu-temperature']) as $CPUTemp) {
/* @var $CPUTemp Temperature */
$status = self::STATUS_OK;
if ($CPUTemp->value > 100) {
$status = self::STATUS_WARNING;
}
}
return max($all_status);
}
public static function parse(string $string)
{
$values = array();
preg_match_all(self::REGEXP, $string, $values);
$count = count($values[1]);
for ($i = 0; $i < $count; $i++) {
$CPUTemp = new Temperature();