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

Show status

parent 56b3967b
No related branches found
No related tags found
No related merge requests found
<?php
namespace Monitor;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
/**
* Description of LoadAvg
*
* @author tibo
*/
class LoadAvg implements SensorInterface {
public function run() {
$process = new Process('cat /proc/loadavg');
$process->run();
return $process->getOutput();
}
}
<?php
namespace Monitor;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
/**
* Description of LoadAvg
*
* @author tibo
*/
class LoadAvg implements SensorInterface {
public function run() {
$process = new Process('cat /proc/loadavg');
$process->run();
return $process->getOutput();
}
}
<?php
namespace Monitor;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
/**
* Description of LoadAvg
*
* @author tibo
*/
class LoadAvg implements SensorInterface {
public function run() {
$process = new Process('cat /proc/loadavg');
$process->run();
return $process->getOutput();
}
}
...@@ -35,8 +35,24 @@ class Disks extends \App\AbstractSensor { ...@@ -35,8 +35,24 @@ class Disks extends \App\AbstractSensor {
} }
public function status() { public function status() {
return self::STATUS_OK; $record = $this->getLastRecord("disks");
if ($record == null) {
return self::STATUS_UNKNOWN;
}
$all_status = [];
foreach ($this->parse($record->disks) as $disk) {
/* @var $disk Disk */
$status = self::STATUS_OK;
if ($disk->usedPercent() > 80) {
$status = self::STATUS_WARNING;
} elseif ($disk->usedPercent() > 95) {
$status = self::STATUS_ERROR;
}
$all_status[] = $status;
}
return max($all_status);
} }
public function parse($string) { public function parse($string) {
......
...@@ -40,7 +40,6 @@ class Reboot extends \App\AbstractSensor { ...@@ -40,7 +40,6 @@ class Reboot extends \App\AbstractSensor {
return self::STATUS_UNKNOWN; return self::STATUS_UNKNOWN;
} }
if ($record->reboot) { if ($record->reboot) {
return self::STATUS_WARNING; return self::STATUS_WARNING;
} }
......
...@@ -54,8 +54,30 @@ class Server extends Model ...@@ -54,8 +54,30 @@ class Server extends Model
return $last_record->version; return $last_record->version;
} }
/**
* Get integer status of server.
* @return int
*/
public function status() { public function status() {
return "OK"; $all_status = [];
foreach ($this->getSensors() as $sensor) {
$all_status[] = $sensor->status();
}
return max($all_status);
}
public function statusString() {
switch ($this->status()) {
case 0:
return "OK";
case 10:
return "WARNING";
case 20:
return "ERROR";
default:
return "Unknown";
}
} }
public function getSensors() { public function getSensors() {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
@foreach($organization->servers as $server) @foreach($organization->servers as $server)
<tr> <tr>
<td>{{ $server->name }}</td> <td>{{ $server->name }}</td>
<td>{{ $server->status() }}</td> <td>{{ $server->statusString() }}</td>
<td>{{ $server->lastRecordTime()->diffForHumans() }}</td> <td>{{ $server->lastRecordTime()->diffForHumans() }}</td>
<td class="text-right"> <td class="text-right">
<a class="btn btn-primary btn-sm" <a class="btn btn-primary btn-sm"
......
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