![]() In a terminal window, enter the following: sudo apt-get install sysstat Allow the process to complete. For Debian and Ubuntu systems, you’ll need to install the sysstat package. Most RHEL-based distributions include this software package. You can also parse the output of top -n1 | grep -i cpu to get the cpu usage, but it only samples for half a second on my linux box and it was way off during heavy load. mpstat Command to Display CPU Activity Mpstat is part of a software bundle called sysstat. I run similar code in a loop within a go routine, then I access the cpu usage when I need it from other go routines. The top command is an interactive system monitor that displays the CPU utilization and the usage of other system resources in real-time. You'll notice that I wait 3 seconds between samples to match top's output, but I have also had good results with 1 or 2 seconds. I sample the /proc/stat file just like tylerl recommends. ![]() ![]() There's also procps, found on, e.g., Ubuntu and CentOS, where the command doesn't work (always indicates 100, because parsing fails due to the line with the CPU figures being formatted differently). Here is a slimmed down version of my solution that answers your specific question. You can display exhaustive system process information about software processes that are running on the router and have controlling terminals. The command in this answer appears to be written for systems where top -v returns procps-ng (e.g., Fedora). I had a similar issue and never found a lightweight implementation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |