Skip to content

Instantly share code, notes, and snippets.

@itiut
Created June 21, 2014 17:47
Show Gist options
  • Save itiut/2cbf1a425bc610bf5a2a to your computer and use it in GitHub Desktop.
Save itiut/2cbf1a425bc610bf5a2a to your computer and use it in GitHub Desktop.
sar -d と sar -x の出力からCPU利用率とI/Oスループットを抽出してプロットする
#!/bin/sh
set -eu
cd $(dirname $0)
join_sar() {
local cpu_out=sar_cpu$1.out
local io_out=sar_io$1.out
local sar_out=sar$1.out
local cpu_out_temp=$cpu_out.temp
local io_out_temp=$io_out.temp
local device=$2
tail -n +3 $cpu_out \
| awk '{ printf "%d %f %f\n", (NR - 1) * 5, $5, $6 }' \
> $cpu_out_temp
echo '0 0.0 0.0' > $io_out_temp
grep -e "$device" $io_out \
| awk '{ printf "%d %f %f\n", NR * 5, $4 * 2^(-11), $5 * 2^(-11) }' \
>> $io_out_temp
echo '# seconds, %user, %system, read[MB/s], write[MB/s]' > $sar_out
join $cpu_out_temp $io_out_temp >> $sar_out
echo "[$0] Write $PWD/$sar_out"
rm $cpu_out_temp $io_out_temp
}
plot() {
local sar_out=sar$1.out
local eps=sar$1.eps
local emf=sar$1.emf
gnuplot <<EOPLT
set key below;
set grid;
set ytics nomirror;
set y2tics;
set xlabel 'Elapsed Time [sec]';
set ylabel 'CPU Usage [%]';
set y2label 'I/O Throughput [MB/s]';
set yrange [0:180];
set y2range [0:180];
set style fill solid 0.1;
set size 2,1;
set terminal postscript eps enhanced color solid;
set output '$eps';
plot '$sar_out' u 1:(\$2+\$3) w filledcurves x1 t '%system', \
'$sar_out' u 1:2 w filledcurves x1 t '%user', \
'$sar_out' u 1:4 w l t 'Read' axes x1y2, \
'$sar_out' u 1:5 w l t 'Write' axes x1y2;
set size 1,1;
set terminal emf size 960,480;
set output '$emf';
replot;
set terminal png size 960,480;
set output 'sar$1.png';
replot;
EOPLT
echo "[$0] Write $PWD/$eps"
echo "[$0] Write $PWD/$emf"
}
if [ $# -ne 2 ]; then
echo "Usage: [$0] directory device"
exit
fi
cd $1
for i in $(seq 1 22); do
if [ ! -f sar_cpu$i.out ]; then
continue
fi
{
join_sar $i $2
plot $i
} &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment