Terminal Perf Graphs in one Command

Sysstat and Graphs

If you have the sysstat package set up on your server, then you likely already know you can get historical CPU performance information with sar like this:

$ sar | head
Linux 4.15.0-10-generic (cage) 27/03/18 _x86_64_ (4 CPU)
00:00:01 CPU %user %nice %system %iowait %steal %idle
00:01:01 all 1.79  0.00  21.70   0.03    0.00   76.47
00:02:01 all 1.28  0.01  10.09   0.01    0.00   88.62
00:03:01 all 1.39  0.00  6.09    0.01    0.00   92.51
00:04:01 all 1.20  0.00  5.23    0.02    0.00   93.55
00:05:01 all 1.26  0.00  5.74    0.01    0.00   92.98
00:06:01 all 1.30  0.00  20.46   0.83    0.00   77.40
00:07:01 all 0.82  0.01  9.28    0.02    0.00   89.87

and you also probably know you can get the history of various metrics, not just CPU, eg disk IO, run queue size, and so on.

This info is great, but sometimes you just want a quick view of what’s going on.

You can faff around with some platform to try and get the information graphed in a sophisticated way if you have the time, skills and inclination. But mostly I just want a quick view with the least fuss.

So I used this script and bundled it into a container image to produce ascii graphs with one command. They look like this (click here to enlarge):

sar_report output. Click to enlarge

At first they’re hard to parse, but you quickly get used to them.

They’re great for quickly seeing when things went south, and what else went on at the time.

Running

To run this on your host, do:

$ docker run \
  -e SAR_REPORT_DAY="${SAR_REPORT_DAY:-$(date +%d)}" \
  -e LINES=${LINES:-$(stty size | awk '{print $1}')} \
  -e COLUMNS=${COLUMNS:-$(stty size | awk '{print $NF}')} \
  -e TERM=${TERM:-xterm} \
  -v /var/log/sysstat:/var/log/sysstat:ro \
  imiell/sar_report

The -e arguments set the ‘day’ to report on (defaults to today’s day), and pass the terminal settings to

The -v flag mounts the /var/log/systat folder into the container (it is mounted read-only, to reduce any risk/fear of the Docker container messing up your host’s filesystem).

To change the day, set (eg) SAR_REPORT_DAY=01 in the terminal before running the command.

You’ll need Docker (and sysstat, of course) installed and running on your host for this to work out of the box.

Or you can run the command:

$ ./sar_report

from the repo‘s folder.

Suggestions? Problems?

The code is here and is a work in progress – please suggest changes/raise bugs etc. on Github.

 


If you like this post, you might like  Learn Git the Hard WayLearn Bash the Hard Way or Docker in Practice

learngitthehardway

hero

 

Get 39% off Docker in Practice with the code: 39miell2


 

 

 

 

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s