-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
910f993
commit 493107e
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Sarfraz | ||
* Date: 7/10/2019 | ||
* Time: 2:39 PM | ||
*/ | ||
|
||
namespace Sarfraznawaz2005\ServerMonitor\Checks\Server; | ||
|
||
use Sarfraznawaz2005\ServerMonitor\Checks\Check; | ||
|
||
class AvgCpuUsage implements Check | ||
{ | ||
private $percent; | ||
|
||
/** | ||
* Perform the actual verification of this check. | ||
* | ||
* @param array $config | ||
* @return bool | ||
*/ | ||
public function check(array $config): bool | ||
{ | ||
$this->percent = round($this->getCPUUsagePercentage(), 2); | ||
|
||
$failPercentage = $config ['fail_percentage']; | ||
|
||
return !($this->percent >= $failPercentage); | ||
} | ||
|
||
protected function getCPUUsagePercentage() | ||
{ | ||
$cpu = shell_exec("grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'"); | ||
|
||
return (float)$cpu; | ||
} | ||
|
||
/** | ||
* The error message to display in case the check does not pass. | ||
* | ||
* @return string | ||
*/ | ||
public function message(): string | ||
{ | ||
return 'Average CPU usage at: ' . $this->percent . '%'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters