Easily graph data in shell and Python

Introduction

It is often easy and often large to graph the data acquired on a regular basis. However, I think that the hurdles are high for inexperienced people, so I hope to provide an entrance. (The rest is python mission)

Graphing meminfo

As an example, let's easily graph the information of / proc / meminfo acquired regularly with shell and python.

It is assumed that the meminfo information is saved in the format <date> / <hour, minute, second> /meminfo.log (example: 20160224/105312 / meminfo.log).

The format of meminfo looks like this

MemTotal:         511476 kB
MemFree:          269240 kB
Buffers:           13936 kB
Cached:            56044 kB
SwapCached:            0 kB
Active:            36944 kB
Inactive:          47324 kB
Active(anon):      14648 kB
Inactive(anon):      208 kB
Active(file):      22296 kB
Inactive(file):    47116 kB
Unevictable:           0 kB
Mlocked:               0 kB
HighTotal:             0 kB
HighFree:              0 kB
LowTotal:         511476 kB
LowFree:          269240 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         14304 kB
Mapped:            16548 kB
Shmem:               568 kB
Slab:               7416 kB
SReclaimable:       2600 kB
SUnreclaim:         4816 kB
KernelStack:         504 kB
PageTables:          784 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      255736 kB
Committed_AS:     195212 kB
VmallocTotal:    1548288 kB
VmallocUsed:        8428 kB
VmallocChunk:    1350896 kB

Suppose you want to graph the value of Committed_AS in meminfo

$ find . -name 'meminfo.log' | sort | xargs grep Committed_AS

Then, the following output is obtained.

./20160211/190409/meminfo.log:Committed_AS:     389260 kB
./20160211/191528/meminfo.log:Committed_AS:     389300 kB
./20160211/192648/meminfo.log:Committed_AS:     394600 kB

This is further processed by gawk into the date number format.

$ find . -name 'meminfo.log' | sort | xargs grep Committed_AS | gawk 'match($0, /\/([0-9]+)\/([0-9]+).*[0-9]+ kB/, a) {print a[1] a[2], $2}'
20160211190409 389260
20160211191528 389300
20160211192648 394600

Then draw this with matplot

plot_date.py


#!/usr/bin/env python3 

import matplotlib.pyplot as plt

from datetime import datetime as dt

import sys

[date, y] = zip(*[l.split() for l in sys.stdin])
date=[dt.strptime(d, "%Y%m%d%H%M%S") for d in date]

plt.plot(date,y)

plt.show()
$ find . -name 'meminfo.log' | sort | xargs grep Committed_AS | gawk 'match($0, /\/([0-9]+)\/([0-9]+).*[0-9]+ kB/, a) {print a[1] a[2], $2}' | python3 plot_date.py

mem_plot.png

Recommended Posts

Easily graph data in shell and Python
Hashing data in R and Python
Graph time series data in Python using pandas and matplotlib
Graph drawing in python
Draw graph in python
Python variables and data types learned in chemoinformatics
Receive and display HTML form data in Python
Data analysis: Easily apply descriptive and inference statistics to CSV data in Python
Handle Ambient data in Python
Easily format JSON in Python
Full-width and half-width processing of CSV data in Python
Run shell commands in python
Stack and Queue in Python
Unittest and CI in Python
I created a stacked bar graph with matplotlib in Python and added a data label
How to execute external shell scripts and commands in python
Graph the Poisson distribution and the Poisson cumulative distribution in Python and Java, respectively.
Get Leap Motion data in Python.
MIDI packages in Python midi and pretty_midi
Difference between list () and [] in Python
Difference between == and is in python
View photos in Python and html
Read Protocol Buffers data in Python3
Sorting algorithm and implementation in Python
Run shell command / python in R
Manipulate files and folders in Python
About dtypes in Python and Cython
Handle NetCDF format data in Python
Assignments and changes in Python objects
Check and move directories in Python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Function synthesis and application in Python
Export and output files in Python
Ant book in python: Sec. 2-5 Graph
Reverse Hiragana and Katakana in Python2.7
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
Create and read messagepacks in Python
[Python] [3D line graph] Multiple data in one graph, axis values in characters
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part1-
processing to use notMNIST data in Python (and tried to classify it)
Create your own graph structure class and its drawing in python
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part2-
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part4-
Solving AOJ's Algorithm and Introduction to Data Structures in Python -Part3-
Overlapping regular expressions in Python and Java
Get additional data in LDAP with python
Data pipeline construction with Python and Luigi
Differences in authenticity between Python and JavaScript
Notes using cChardet and python3-chardet in Python 3.3.1.
Modules and packages in Python are "namespaces"
Avoid nested loops in PHP and Python
Data input / output in Python (CSV, JSON)
Differences between Ruby and Python in scope
difference between statements (statements) and expressions (expressions) in Python
Eigenvalues and eigenvectors: Linear algebra in Python <7>
Try working with binary data in Python
Implementation module "deque" in queue and Python
Easily use your own functions in Python
Line graphs and scale lines in python
Differences in syntax between Python and Java