«

»

Oct 11 2015

cpustat_v1.0

For more information and update , please visit Github

Overview

Click here for Chinese README.中文文档

A very simple cpu usage percentages monitor tools. Simply calculate and output cpu usage percentages in text. Two versions coding by shell and php.

The reason why I made this

(You can skip this phase. This is just my complaint)

Nowadays there are a lot of tools that can collect, report, or save percentage of CPU time. They are very powerful because they can record cpu performance and save log, or they have a good readability with a GUI, such as sar and nmon.

But I didn’t find a tool which can simply output a percentage of cpu time.

Earlier I wrote a system status monitor, so I need to find some tools to monitor the usage of cpu, memory and disk. I chose ‘free’ and ‘df’ to watch memory and disk. However, I couldn’t find a simple tool to monitor cpu. I tried top and found it couldn’t unfold cpu without interactive mode. Similarly found sar only record log and nmon only work in interactive mode.

Even though they are powerful tools, and maybe they have a mode to output a simple or complex output, I only need a very simple tool to output a simple value of cpu usage, no need of history log, no need of interactive mode.

So I decided to write a tool to make myself satisfied.

Note :

  • This project use ‘cat /proc/stat’ to collect information, using regex, so only work with Linux 2.6.24 and newer version because there are 9 columns. See in:http://www.linuxhowtos.org/System/procstat.htm
  • Because Bash doesn’t support floating calculation, so there is only integer %. I don’t want to use bc to support floating calculation, because there is no need of such exact computation.

Install

Just copy files to your destination computer. Give bash_cpustat.sh execute permission if you need it.

Usage

PHP

Run php_cpustat.php in php-cli, Or open it in brower (need http service):

php php_cpustat.php level=s

curl php_cpustat.php level=s

Notice :If you want to change output level, edit file and change the value of $inforlevel = ‘a’;

php php_cpustat.php level=a

curl php_cpustat.php level=a

Notice :If you open php_cpustat.php in brower, the output may seem in a mess because the it use LF for newline, not CRLF.

Bash

Simply run like this (execute permission needed):

You can use -h for more information.

bash_cpustat.sh

Contributor

Thank 梅桐天土小星星 for fixing grammatical errors of README.

1 comment

  1. 菠萝格格の博客志

    纯英文的

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据