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)
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
Recommended Posts