Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

Released cpu-stat: command line CPU usage statistics for Linux

$
0
0

I have released the first public version of cpu-stat, a command line program which provides CPU usage statistics for linux systems. Source code is open and available on GitHub.


Released cpu-stat: command line CPU usage statistics for Linux

If you follow my blog you might have read my last post about “ A C++ program to get CPU usage from command line in Linux ” published on the 17th of December. There I mentionedI was working on a more advanced program to get CPU usage stats on Linux systems. That program is cpu-stat and it’s now publicly available.

I created cpu-stat to have a quick and simple answer to the question “what’s the CPU usage of my system right now?” and that’s what you get when you runthe program with no options.

The intended use is for scripts or system monitoring tools which do not want to parse /proc/stat directly to get CPU usage stats.

I should probably mention that cpu-stat requires a Linux kernel2.6.33 or newer, but this shouldn’t be a problem in most cases as that version has been released over 6 years ago and it’s not mantained any more.

Features

These are the main features of the current version (0.01.02):

single number mode: ideal for scripts and piping. full stats mode: show percentage times for all CPU states. verbose mode: includes info labels to better understand stats. variable output precision: control decimal precision of stats. support for multiple CPUs: print stats for one, all and total CPUs. variable delay time: decide delay time between snapshots sampling.

All these features are accessible via a simple command line interface as showed in the next section.

Examples

Here you can find examples of few executions of cpu-stats with different options.

Print percentage of active time for total CPU:

$ cpu-stat
2.50

Print percentage of active time for all CPUs in verbose mode (with labels):

$ cpu-stat -a -v
tot] 5.00%
0] 0.00%
1] 0.00%
2] 20.00%
3] 0.00%

Print percentage of idle time (state 3) for CPU 2 using 4 digits as decimal precision:

$ cpu-stat -s 3 -c 2 -p 4
100.0000

Print percentage of all states for all CPUs in verbose mode (with labels):

$ cpu-stat -a -v -f
tot] usr: 0.00% | sys: 0.00% | nic: 0.00% | idl: 100.00% | iow: 0.00% | hir: 0.00% | sir: 0.00% | ste: 0.00% | gue: 0.00% | gun: 0.00% |
0] usr: 0.00% | sys: 0.00% | nic: 0.00% | idl: 100.00% | iow: 0.00% | hir: 0.00% | sir: 0.00% | ste: 0.00% | gue: 0.00% | gun: 0.00% |
1] usr: 0.00% | sys: 0.00% | nic: 0.00% | idl: 100.00% | iow: 0.00% | hir: 0.00% | sir: 0.00% | ste: 0.00% | gue: 0.00% | gun: 0.00% |
2] usr: 0.00% | sys: 0.00% | nic: 0.00% | idl: 100.00% | iow: 0.00% | hir: 0.00% | sir: 0.00% | ste: 0.00% | gue: 0.00% | gun: 0.00% |
3] usr: 0.00% | sys: 0.00% | nic: 0.00% | idl: 90.91% | iow: 9.09% | hir: 0.00% | sir: 0.00% | ste: 0.00% | gue: 0.00% | gun: 0.00% | Download

You can download cpu-stat from GitHub. The source code is released under the MIT license.

To build the project on Linux you will need scons , a software construction tool written inpython.

Conclusion

If you found cpu-stat any useful, please share this post on social media using the social buttons below.

If youhave any question feel free to leave a comment here. Whereas open a new issue on GitHub for bugs and features requests.

Subscribe

Don’t forget to subscribe to the blog newsletter to get notified of future posts and projects (once a week).

You can also get updates following me on Google+ , LinkedIn and Twitter .


Viewing all articles
Browse latest Browse all 11063

Trending Articles