vmstatの結果をgnuplotでグラフ化する
tipsです。
vmstatの結果をファイルに出力
vmstat -n -S m -a 1 | awk '{print strftime("%H:%M:%S"), $0} { system(":") }' >> vmstat.log
リダイレクトがうまくいかず、調べたところ、
(今さら) vmstat の結果に時間をつけてファイルに出力する - あしのあしあと
に辿り着きました。ありがたや。
gnuplotの設定
以下を適当なファイル名(ここでは「vmstat2graph」)で保存。
#!/usr/bin/gnuplot # 出力はPNG、サイズは 640x640 set terminal png size 640,640 # 出力ファイル名の設定 set output "vmstat.png" # 2行1列でグラフを描画 set multiplot layout 2, 1 # CPUグラフ set size 1.0,0.35 set title "CPU usage" set ylabel "percent" set xdata time set timefmt "%H:%M:%S" set format x "%H:%M:%S" set xtics rotate #set style fill transparent solid 0.5 noborder plot "vmstat.log" using 1:15 title "system" with lines, \ "vmstat.log" using 1:14 title "user" with lines, \ "vmstat.log" using 1:16 title "idle" with lines # メモリグラフ set size 1.0,0.35 set title "memory usage" set ylabel "size(M Bytes)" set xdata time set timefmt "%H:%M:%S" set format x "%H:%M:%S" set xtics rotate #set style fill transparent solid 0.5 noborder plot "vmstat.log" using 1:4 title "swap" with lines, \ "vmstat.log" using 1:6 title "inact" with lines, \ "vmstat.log" using 1:7 title "active" with lines, \ "vmstat.log" using 1:5 title "free" with lines
chmod +x しておく。
グラフ化
vmstat.logが存在する状態で、vmstat2graphを実行すると・・・
めでたし。