Skip to content

Instantly share code, notes, and snippets.

@gcphost
Created July 10, 2015 21:29
Show Gist options
  • Save gcphost/92aa9af61d919d348934 to your computer and use it in GitHub Desktop.
Save gcphost/92aa9af61d919d348934 to your computer and use it in GitHub Desktop.
PHP Simple Stats, CPU, Memory, Disc and Load Usage
<?php
$load=sys_getloadavg();
$results=array(
'memory' => round(exec("printf \$(free -m| grep Mem | awk '{ print \$3/\$2*100 }')"),2),
'disc' => (100-round(disk_free_space(getcwd())/disk_total_space (getcwd()) * 100,2)),
'cpu' => round(exec("grep 'cpu ' /proc/stat | awk '{cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage}'"),2),
'load' => $load[0]
);
die(json_encode($results));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment