diff --git a/src/Checks/CpuLoadCheck.php b/src/Checks/CpuLoadCheck.php new file mode 100644 index 0000000..47b6c48 --- /dev/null +++ b/src/Checks/CpuLoadCheck.php @@ -0,0 +1,55 @@ +maxLoad = [$short, $mid, $long]; + + return $this; + } + + public function run(): Result + { + if (! isset($this->maxLoad)) { + throw new Exception('The max average load was not set'); + } + + $result = Result::new(); + + $load = sys_getloadavg(); + + if (! $load) { + return $result->failed('Failed to get system load averages'); + } + + foreach ($this->maxLoad as $index => $max) { + if (is_null($max)) { + continue; + } + + if ($index == count($load)) { + break; + } + + if ($max < $actual = round($load[$index], 2)) { + return $result->failed( + "System average load [{$index}] is at {$max}%, max is configured at {$actual}%", + ); + } + } + + return $result->ok('System load averages are ok'); + } +}