vmstatをgnuplotでグラフ作成
を、ほぼまるまる参考にしてます.ありがとうございます.
変更点はほぼなし
#!/bin/zsh # 【vmstat の出力】 # vmstat -n -S m -a 1 | awk '{print strftime("%H:%M:%S"), $0}' # #11:13:31 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ #11:13:31 r b swpd free inact active si so bi bo in cs us sy id wa st #11:13:31 1 0 0 6 141 307 0 0 48 76 22 20 1 0 99 0 0 #11:13:32 0 0 0 6 141 307 0 0 0 0 14 15 0 0 100 0 0 # # 【vmstat 各項目の意味】 # Memory # swpd: 仮想メモリの量。 # free: 空きメモリの量。 # buff: バッファに用いられているメモリの量。 # cache: キャッシュに用いられているメモリの量。 # inact: アクティブでないメモリの量 (-a オプション)。 # active: アクティブなメモリの量 (-a オプション)。 # # Swap # si: ディスクからスワップインされているメモリの量 (/s)。 # so: ディスクにスワップしているメモリの量 (/s)。 # # IO # bi: ブロックデバイスから受け取ったブロック (blocks/s)。 # bo: ブロックデバイスに送られたブロック (blocks/s)。 # # System # in: 一秒あたりの割り込み回数。クロック割り込みも含む。 # cs: 一秒あたりのコンテキストスイッチの回数。 # # CPU # これらは CPU の総時間に対するパーセンテージである。 # us: カーネルコード以外の実行に使用した時間 (ユーザー時間、nice 時間を含む)。 # sy: カーネルコードの実行に使用した時間 (システム時間)。 # id: アイドル時間。Linux 2.5.41 以前では、IO 待ち時間を含んでいる。 # wa: IO 待ち時間。Linux 2.5.41 以前では、0 と表示される。 # st: 仮想マシンから盗まれた時間。Linux 2.6.11より前では未知。 function print_usage { name=`basename $1` echo "Usage: For example: $name log_file output.png " } #変数の数チェック if [ "$#" -eq 2 ];then echo "ok" else print_usage $0 exit 1 fi vmstatLog=$1 outputFile=$2 gnuplot <<EOF # 出力ファイルをPNGファイルとし、サイズを 640x640 にする set terminal png size 1100,900 # 出力ファイル名の設定 set output "$outputFile" # 1ファイルで縦3,横1のグラフを出力 set multiplot layout 3, 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 "$vmstatLog" using 1:15 title "system" with lines, \ "$vmstatLog" using 1:14 title "user" with lines, \ "$vmstatLog" 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, \ "$vmstatLog" using 1:6 title "inact" with lines, \ "$vmstatLog" using 1:7 title "active" with lines, \ "$vmstatLog" using 1:5 title "free" with lines # ディスク用の設定 set size 1.0,0.35 set title "disk I/O" set ylabel "I/O (blocks/sec)" 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 "$vmstatLog" using 1:10 title "read" with lines, \ "$vmstatLog" using 1:11 title "write" with lines unset multiplot EOF
使い方
vmstatログファイルの作成
$ vmstat 1 | awk '{print strftime("%H:%M:%S"), $0}{fflush()}' >> vmstat.txt
シェルの実行
$ chmod +x vmstat_graph.sh $ ./vmstat_graph <出力したログ・ファイル> <出力するアウトプットファイル>
いやホントありがとうございます.