Giter Site home page Giter Site logo

jiajianwei7 / cpustat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from catscarlet/cpustat

0.0 0.0 0.0 75 KB

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

Shell 52.65% PHP 47.35%

cpustat's Introduction

cpustat

Overview

Click here for Chinese README.中文文档

A very simple CPU usage percentages monitor tools for Linux. 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 uses cat /proc/stat to collect information, using regex, so it only works 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 browser (need http service):

php-cli

Simply run like this:

php php_cpustat.php

php php_cpustat.php level=s

In php-cli, you can change output level directly using parameter 's' or 'a':

php php_cpustat.php a

php php_cpustat.php level=-a

browser

You can open php_cpustat.php in browser. Try to use curl easily:

curl http://localhost/cpustat/php_cpustat.php

curl php_cpustat.php level=s

curl php_cpustat.php level=a

php_cpustat.php don't support parameter in browser yet. You need to change the default output level instead.

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

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


Bash

Simply run like this (execute permission needed):

./bash_cpustat.sh

You can use -h for more information.

bash_cpustat.sh

Contributor

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

cpustat's People

Contributors

catscarlet avatar leviathangirl 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.