Skip to content

Instantly share code, notes, and snippets.

@horsley
Last active December 12, 2015 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save horsley/4721088 to your computer and use it in GitHub Desktop.
Save horsley/4721088 to your computer and use it in GitHub Desktop.
A simple PHP script to get vps's status from solus api
<?php
/**
* A simple PHP script to get vps's status from solus api
*
*/
set_time_limit(180);
$serv_array = array(
array(//an vps
'api_server' => 'https://solus.hostigation.com:5656', //panel login page
'api_key' => 'AAAAA-AAAAA-AAAA',
'api_hash' => 'acec74a2304bf68f28ab5bd0a375dc16219b67e5',
),
array(//another one
'api_server' => 'https://vpsm.frontrangehosting.com:5656',
'api_key' => 'BBBBB-BBBBB-BBBB',
'api_hash' => 'caa293ab6633fd014e8c74a576f01af178f54443',
),
);
define('URL_FORMAT', '%s/api/client/command.php?key=%s&hash=%s&action=info&ipaddr=true&bw=true&mem=true&hdd=true&status=true'); //url key hash
foreach ($serv_array as $server) {
$url = sprintf(URL_FORMAT, $server['api_server'], $server['api_key'], $server[api_hash]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
$data = curl_exec($ch);
curl_close($ch);
preg_match("/<hostname>(.*)<\/hostname>/", $data, $hostname);
preg_match("/<vmstat>(.*)<\/vmstat>/", $data, $vmstat);
preg_match("/<ipaddr>(.*)<\/ipaddr>/", $data, $ipaddr);
preg_match("/<hdd>(.*),(.*),(.*),(.*)<\/hdd>/", $data, $hdd);
preg_match("/<bw>(.*),(.*),(.*),(.*)<\/bw>/", $data, $bw);
preg_match("/<mem>(.*),(.*),(.*),(.*)<\/mem>/", $data, $mem);
$hdd[1] = format_bytes($hdd[1]);
$hdd[2] = format_bytes($hdd[2]);
$mem[1] = format_bytes($mem[1]);
$mem[2] = format_bytes($mem[2]);
$bw[1] = format_bytes($bw[1]);
$bw[2] = format_bytes($bw[2]);
echo "<strong>Server: </strong>$hostname[1]<br />\n";
echo "<strong>Status: </strong>$vmstat[1]<br />\n";
echo "<strong>IP: </strong>$ipaddr[0]<br />\n";
echo "<strong>HDD total: </strong>$hdd[1], <strong>used: </strong>$hdd[2], $hdd[4]%<br />\n";
echo "<strong>Memory total: </strong>$mem[1], <strong>used: </strong>$mem[2], $mem[4]%<br />\n";
echo "<strong>Bandwidth total: </strong>$bw[1], <strong>used: </strong>$bw[2], $bw[4]%<br />\n";
echo "<hr />";
}
function format_bytes($size) {
$units = array(' B', ' KB', ' MB', ' GB', ' TB');
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
return round($size, 2).$units[$i];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment