Skip to content

Instantly share code, notes, and snippets.

@yasushiyy
Created July 2, 2014 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasushiyy/e1e4dc35e24e55e3b750 to your computer and use it in GitHub Desktop.
Save yasushiyy/e1e4dc35e24e55e3b750 to your computer and use it in GitHub Desktop.
vmstatとかiostatを見やすくtailしたい

トラブル時に忘れるのでメモ。

vmstatは横に長いです。特に複数サーバのvmstatを一括で見たいときには邪魔なので、以下のようなワンライナーを使っています。

$ vmstat 1 | egrep --line-buffered "^ +[0-9]" | awk '{OFS=""; print "r=",$1," us=",$13," sy=",$14; fflush()}'

r=2 us=0 sy=0
r=0 us=1 sy=0
r=0 us=1 sy=1
r=0 us=1 sy=0

いっそそのままCSVにしちゃってもよいでしょう。

$ echo "r,us,sy"; vmstat 1 | egrep --line-buffered "^ +[0-9]" | awk '{OFS=","; print $1,$13,$14; fflush()}'

r,us,sy
2,0,0
0,1,0
0,1,1

iostatは縦にも横にも長いです。特定デバイスのr/s, w/sだけ見たいときには、以下のようにやっています。

$ iostat -xd 1 | egrep --line-buffered "Device|xvda[0-9]" | awk '{OFS=""; ORS=""; if ($1=="Device:") print "\n"; else print $1,"=",$4,"|",$5," "; fflush()}'

xvda1=0.00|0.00 xvda2=0.00|0.00 xvda3=0.36|14.02
xvda1=0.00|0.00 xvda2=0.00|0.00 xvda3=0.00|0.00
xvda1=0.00|0.00 xvda2=0.00|0.00 xvda3=0.00|20.00
xvda1=0.00|0.00 xvda2=0.00|0.00 xvda3=0.00|0.00
xvda1=0.00|0.00 xvda2=0.00|0.00 xvda3=0.00|0.00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment