Skip to content
Snippets Groups Projects
Commit b1c08aaf authored by Tibo's avatar Tibo
Browse files

add check for load avg

parent 1c51c06c
No related branches found
No related tags found
No related merge requests found
Pipeline #3779 failed
......@@ -10,6 +10,18 @@ namespace App;
abstract class AbstractSensor implements Sensor
{
private $server;
public function __construct (?Server $server = null)
{
$this->server = $server;
}
protected function server() : Server
{
return $this->server;
}
public function name() : string
{
return (new \ReflectionClass($this))->getShortName();
......
......@@ -40,10 +40,18 @@ class LoadAvg extends AbstractSensor
public function status(array $records) : int
{
$max = $this->server()->info()->cpuinfo()["threads"];
foreach ($records as $record) {
$load = $this->parse($record->loadavg);
if ($load > $max) {
return \App\Status::WARNING;
}
}
return \App\Status::OK;
}
public function parse($string)
public function parse($string) : float
{
return current(explode(" ", $string));
}
......
......@@ -137,7 +137,7 @@ class Server extends Model
$sensors = [];
foreach (self::$sensors as $sensor) {
$sensors[] = new SensorWrapper(new $sensor(), $records);
$sensors[] = new SensorWrapper(new $sensor($this), $records);
}
return $sensors;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment