Giter Site home page Giter Site logo

cpu-stat's Introduction

cpu-stat

A command line program to get CPU usage statistics on Linux systems.

cpu-stat

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 run the 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.

For people interested in understanding more about how things work under the hood, I wrote a tutorial describing a much simpler version of this program and providing more information on the different CPU states.

NOTE: cpu-stat requires Linux kernel 2.6.33 or newer.

Installation

To build cpu-stat you will need SCons.

simple build

This will build cpu-stat in debug mode. Executable file will be in bin/debug.

scons

build in release mode

This will build cpu-stat in release mode. Executable file will be in bin/release.

scons mode=release

install release build

This will install cpu-stat in /usr/bin/.

sudo scons mode=release install

clean release build

This will remove all files generated by a release build.

sudo scons mode=release -c install

You can omit install at the end to remove only build files and keep the installed executable.

Usage

Print options

flag description default
-a | --all print active time percentage for all CPUs, starting with total false
-c <cpu> print stats only for selected CPU. -
-f | --full-state print time percentage of all states false
-p <precision> set the decimal precision of printed numbers 2
-s <state> print time percentage for specific state [0-9] -
-v | --verbose enable verbose mode false

Other options

flag description default
-d <time> set delay time (in ms) between 2 snapshots of CPU data 100
-h | --help print help -
--version print the version number -

Examples

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% |

Contribute

If you want to contribute to cpu-stat check out this guide about how to contribute to an open source project on GitHub first.

cpu-stat's People

Contributors

vivaladav avatar timothydjones avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.