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

add memory usage check

parent 98ee7b2d
No related branches found
No related tags found
No related merge requests found
Pipeline #3781 passed
......@@ -48,6 +48,13 @@ class MemInfo extends AbstractSensor
public function status(array $records) : int
{
foreach ($records as $record) {
$mem = $this->parseMeminfo($record->memory);
if ($mem->usedRatio() > 0.8) {
return \App\Status::WARNING;
}
}
return \App\Status::OK;
}
......
......@@ -19,15 +19,21 @@ class Memory
public $free;
public $cached;
public function __construct($total, $free, $cached)
public function __construct(int $total, int $free, int $cached)
{
$this->total = $total;
$this->free = $free;
$this->cached = $cached;
}
public function used()
public function used() : int
{
return $this->total - $this->free - $this->cached;
}
public function usedRatio() : float
{
return $this->used() / $this->total;
}
}
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