runthis Posted April 7, 2013 Share Posted April 7, 2013 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>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.