-
Notifications
You must be signed in to change notification settings - Fork 1
/
disk_util.sh
executable file
·88 lines (73 loc) · 3.03 KB
/
disk_util.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# Check for the input arguments
while getopts "b:a:s:r:d:h" opt
do
case "${opt}" in
b)
DSTATS_BEFORE="${OPTARG}"
;;
a)
DSTATS_AFTER="${OPTARG}"
;;
s)
IOSTAT="${OPTARG}"
;;
r)
RESULT_DIR="${OPTARG}"
;;
d)
DEVICES+=("${OPTARG}")
;;
h)
usage
;;
*)
usage
;;
esac
done
for dev in "${DEVICES[@]}"
do
R_SEC_BEFORE=$(grep $dev ${DSTATS_BEFORE} | awk '{ print $6 }')
W_SEC_BEFORE=$(grep $dev ${DSTATS_BEFORE} | awk '{ print $10 }')
R_SEC_AFTER=$(grep $dev ${DSTATS_AFTER} | awk '{ print $6 }')
W_SEC_AFTER=$(grep $dev ${DSTATS_AFTER} | awk '{ print $10 }')
DIFF_SEC_READ=$(expr ${R_SEC_AFTER} - ${R_SEC_BEFORE})
DIFF_SEC_WRITE=$(expr ${W_SEC_AFTER} - ${W_SEC_BEFORE})
DIFF_BYTES_READ=$(expr ${DIFF_SEC_READ} \* 512)
DIFF_BYTES_WRITE=$(expr ${DIFF_SEC_WRITE} \* 512)
DIFF_KB_READ=$(expr ${DIFF_BYTES_READ} / 1024)
DIFF_KB_WRITE=$(expr ${DIFF_BYTES_WRITE} / 1024)
DIFF_MB_READ=$(expr ${DIFF_BYTES_READ} / 1024 / 1024)
DIFF_MB_WRITE=$(expr ${DIFF_BYTES_WRITE} / 1024 / 1024)
DIFF_GB_READ=$(expr ${DIFF_BYTES_READ} / 1024 / 1024 / 1024)
DIFF_GB_WRITE=$(expr ${DIFF_BYTES_WRITE} / 1024 / 1024 / 1024)
echo "${dev},TOTAL_READS(KB),${DIFF_KB_READ}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},TOTAL_WRITES(KB),${DIFF_KB_WRITE}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},TOTAL_READS(MB),${DIFF_MB_READ}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},TOTAL_WRITES(MB),${DIFF_MB_WRITE}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},TOTAL_READS(GB),${DIFF_GB_READ}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},TOTAL_WRITES(GB),${DIFF_GB_WRITE}" >> ${RESULT_DIR}/diskstat.csv
# Add two blank lines
echo "," >> ${RESULT_DIR}/diskstat.csv
done
for dev in "${DEVICES[@]}"
do
# remove suffix starting with "p"
RM_SF_DEV_NAME=${dev%p*}
cat ${IOSTAT} | grep $RM_SF_DEV_NAME > iostat.out.txt
R_MB_PER_SEC=$(cat iostat.out.txt | awk '{print $6 }' | awk '{ sum += $1; n++ } END { if (n > 0) print (sum / n); }')
W_MB_PER_SEC=$(cat iostat.out.txt | awk '{print $7 }' | awk '{ sum += $1; n++ } END { if (n > 0) print (sum / n); }')
AVG_RQ_SZ=$(cat iostat.out.txt | awk '{print $8 }' | awk '{ sum += $1; n++ } END { if (n > 0) print (sum / n); }')
AVG_QU_SZ=$(cat iostat.out.txt | awk '{print $9 }' | awk '{ sum += $1; n++ } END { if (n > 0) print (sum / n); }')
DEV_UTIL=$(cat iostat.out.txt | awk '{print $14 }' | awk '{ sum += $1; n++ } END { if (n > 0) print (sum / n); }')
echo "${dev},rMB/s,${R_MB_PER_SEC}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},wMB/s,${W_MB_PER_SEC}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},AVGRQ-SZ,${AVG_RQ_SZ}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},AVGQU-SZ,${AVG_QU_SZ}" >> ${RESULT_DIR}/diskstat.csv
echo "${dev},DEV_UTIL,${DEV_UTIL}" >> ${RESULT_DIR}/diskstat.csv
echo "," >> ${RESULT_DIR}/diskstat.csv
rm iostat.out.txt
done
# TODO Change script to plot the statistics for all devices
"$(pwd)"/system_util/plot_iostat.py -i ${IOSTAT} -o ${RESULT_DIR}/plots -s ${DEVICES[0]}