Jump to content

Find CPU Percentage Your Using


Recommended Posts

If you are on a Shared server this code would be obviously different and would not work with safe mode on, however for those of you with Dedicated or VPS servers, this works great on removing the root processes and focuses on your games CPU usage. This is on a Centos 6 machine, sum variable "$9" may need to be adjusted for your OS.

Function displays percentage


$cpu_usage=shell_exec("top -b -n 1 -u USERNAME | awk 'NR>7 { sum += $9; } END { print sum; }'");



Simple 'if' usage displaying colors, feel free to improve this example


if($cpu_usage < 20){ $color='lime'; }
if($cpu_usage > 19){ $color='green'; }
if($cpu_usage > 45){ $color='orange'; }
if($cpu_usage > 65){ $color='yellow'; }
if($cpu_usage > 85){ $color='red'; }

$cpu_usage="<font color='{$color}'>{$cpu_usage}%</font>";
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...