Use Google APIs in Linux to plot the CPU usage of processes

Source: Internet
Author: User

Thanks to grapeot for its inspiration, powershell is used to draw a pie chart showing the CPU usage of processes. I also made a Linux version. I am not familiar with gnuplot and do not know if I can draw a pie chart. Here I use a simple and easy-to-use Google API. First, let's take a look at the static pie chart of the Google chart API:

 

 

Let's take a look at the pie chart in the visualization API just released by Google recently (click here to view the actual effect. below is just, I don't know howArticleEmbedded in JSCode......) :

 

The following is the bash script code (this editor does not support bash code highlighting ...... I will use PS highlight instead, but it's strange ......) :

1 # ! /Bin/bash
2
3 Function Gen_chart (){
4 Chlorophyll = " Chlorophyll = $1 " ; CHD = " CHD = T: $2 " ; Shift
5 While [ $ # -GT 0]; do chlorophyll = "$ {chlorophyll} | $1"; CHD = "$ {CHD}, $2"; shift; done
6
7 # Url = "http://chart.apis.google.com/chart? CHS = 500x200 & CHT = P3 & chtt = Top + 10 + processes + running & $ chlorophyll & $ CHD"
8 URL = " Http://home.ustc.edu.cn /~ Stephen 1/pschart.html? Chtt = Top + 10 + processes + running & $ chlorophyll & $ CHD "
9 Chrome " $ URL "   2 >/ Dev / Null
10 }
11
12 Gen_chart 'ps - EO " % C "   -- Sort =- Pcpu | Head - N 11   | Tail - N 10 `
13

The principle is very simple. First, call the ps command to sort and print the CPU usage of each process, and then extract the first 10 items. Then, let's hand over the rest to Google API :-)

--------------------------- Division line ---------------------------

Thank you for sharing grapeot. I'm amazed at the power of powershell. I thought that PS was just an upgraded version of CMD, but I only added some gadgets. Now I find that my intuition is wrong again. From the introduction of grapeot, I think the essence of PS lies in the object-oriented idea. commands are not transmitted between texts, but objects. If PS can create a pipeline that supports object passing, it may be more powerful!

Microsoft not only strives to lower the threshold for end users to use computers and enhance user experience, but also strives to lower the threshold for developers, which also enables it to have a large number of development teams in the market. The threshold for Linux development is too high. However, the advantage is that the code quality is generally high,ProgramThe execution efficiency is high, but the user is too poor ......

-------------------------- Split line ----------------------------

Who can tell me how to insert JavaScript code directly in this blog post and run it? In addition, if you want to add a bash code block to the editor, who should you respond? Thank you for your support ~

 

Reprinted please indicate the source:Http://www.cnblogs.com/stephenjy/archive/2010/02/22/1671064.html  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.