Last active
February 3, 2018 03:02
-
-
Save davidsword/9efeecac8769887a2a2afb038011153a to your computer and use it in GitHub Desktop.
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
<? | |
/* ===================================================================================================== | |
/* !GEEKLET SERVER TOP */ | |
/* | |
/* Read a serialized array of $cpu, $memory, $load, $time, $hdd, from remote /server_top.php | |
/* Output in text progress bars | |
/* | |
/* By davidsword.ca | |
/* | |
/* ---------------------------------------------------------------------------------------------------*/ | |
/* ===================================================================================================== | |
/* !SETTINGS */ | |
/* ---------------------------------------------------------------------------------------------------*/ | |
date_default_timezone_set('America/Vancouver'); | |
$serverTopURL = "https://example.com/server_top.php"; | |
$serverName = "Amazon Server"; | |
$now = date('H:i:s'); | |
$warningPoint = 95; | |
$warningSymbl = '!'; | |
/* ===================================================================================================== | |
/* !GET */ | |
/* ---------------------------------------------------------------------------------------------------*/ | |
$ch = curl_init($serverTopURL) or die("curl issue"); | |
$curl_options = array( | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_HEADER => false, | |
CURLOPT_FOLLOWLOCATION => false, | |
CURLOPT_ENCODING => "", | |
CURLOPT_AUTOREFERER => true, | |
CURLOPT_CONNECTTIMEOUT => 7, | |
CURLOPT_TIMEOUT => 7, | |
CURLOPT_MAXREDIRS => 3, | |
CURLOPT_SSL_VERIFYHOST => false, | |
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13" | |
); | |
curl_setopt_array($ch, $curl_options); | |
$curlcontent = curl_exec( $ch ); | |
curl_close( $ch ); | |
/* ===================================================================================================== | |
/* !READ */ | |
/* ---------------------------------------------------------------------------------------------------*/ | |
$stats = unserialize($curlcontent); | |
$statTime = date('H:i',strtotime(date('Y-m-d').$stats[3])); | |
$statCPU = makeprogressbar($stats[0]); //% | |
$statMEM = makeprogressbar($stats[1]); //% | |
$statLD = makeprogressbar($stats[2]); //1 second == 100% | |
$statHDD = makeprogressbar($stats[4]); //% | |
/* ===================================================================================================== | |
/* !MAKE */ | |
/* ---------------------------------------------------------------------------------------------------*/ | |
echo "# {$serverName} {$statTime} | |
--------------------------------- | |
CPU {$statCPU} | |
MEM {$statMEM} | |
LOA {$statLD} | |
HDD {$statHDD}"; | |
function makeprogressbar($pafter) { | |
global $warningPoint, $warningSymbl; | |
$progressleft = $progress = ''; | |
$symbol = ($pafter >= $warningPoint) ? $warningSymbl : "="; | |
for ($i=0;$i < ($pafter/5); $i++) | |
$progress .= $symbol; | |
for ($i=0;$i <= ((100-$pafter)/5); $i++) | |
$progressleft .= " "; | |
return "[{$progress}>{$progressleft}] {$pafter}%"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment