Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:32:07+00:00 2026-06-15T22:32:07+00:00

I have a task which consumes arbit CPU and memory over time. It gives

  • 0

I have a task which consumes arbit CPU and memory over time. It gives me an output executing the following linux command:

mpstat -u 1 -P ALL

The output looks like:

02:22:14 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
02:22:15 PM  all    4.51    0.00    0.11    0.00    0.00    0.00    0.00    0.00   95.37
02:22:15 PM    0    0.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00   99.00
02:22:15 PM    1   **78.22**    0.00    0.99    0.00    0.00    0.00    0.00    0.00   20.79

02:22:15 PM    2    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
02:22:15 PM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
02:22:15 PM    4    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM    5    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM    6    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
02:22:15 PM    7    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM    8    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM    9    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   10    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   11    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   12    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   13    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   14    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   15    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
02:22:15 PM   16    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   17    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   18    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   19    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
02:22:15 PM   20    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   21    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   22    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
02:22:15 PM   23    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00

I want to grab the value located in 4th column and 3rd row a[3][4] i.e 78.22 every 20 seconds in bash/python/perl.
So the script I want, will execute the mpstat command and print out the value in the specified column and based on the values it creates a graph. I was thinking of appending the required value in a .dat file and run a gnuplot or and app which creates the graph.

Any suggestion on how to go?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:32:08+00:00Added an answer on June 15, 2026 at 10:32 pm

    You can get the 3rd row and 4th cell using awk. The following code grabs this cell from mpstat‘s output and appends it along with the current UNIX timestamp to a statistics file.

    mpstat -u 1 -P ALL | awk 'NR==4 {print systime(), $4}' >> stats.txt
    

    To run this command every 20 seconds:

    watch -n 20 "mpstat -u 1 -P ALL | awk 'NR==4 {print systime(), \$4}' >> stats.txt"
    

    Then plot with gnuplot:

    cat stats.txt | gnuplot -p -e 'set datafile separator " "; plot "-" using 1:2 with lines'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following design: There is a Task which extends TimerTask and it
I have task which should be done reapited daily for given time. I have
I have a simple rake task which consumes pretty much data via ActiveRecord. (contacts
i have task which takes a parameter and has three modes of results Example
I have a task which has to be run everyday. I will get just
I have a model Task which will HABTM many TaskTargets. When it comes to
I'm using dhtmlx Gantt Chart UI component which have task list and graphical chart.
I have an interesting scenario. I have a task model which has a task
This is a simplified task which I have to solve in real project. In
I have a task/mini project to complete which is along the lines of GUI

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.