pmrep: fix archive end time reporting
[pcp.git] / qa / 975
blob826613c0f71cff2615cca872faa47351317d4ba6
1 #!/bin/sh
2 # PCP QA Test No. 975
3 # Exercise iostat2pcp with locally installed iostat.
5 # Copyright (c) 2014 Red Hat.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 # get standard environment, filters and checks
12 . ./common.product
13 . ./common.filter
14 . ./common.check
16 which iostat >/dev/null || _notrun "No local iostat binary found"
17 # check iostat looks like right version
19 for opt in t x
21 if iostat -\? 2>&1 | grep ".-[a-zA-Z]*$opt" >/dev/null
22 then
24 else
25 _notrun "installed iostat does not have a -$opt option"
27 done
29 which sar >/dev/null 2>&1 || _notrun "sar not installed"
30 version=`sar -V 2>&1 | sed -n -e '/sysstat version /{
31 s/.* //
33 }'`
34 case "$version"
36 7.0.*) # too old
37 _notrun "sysstat version $version too old"
39 '') # not sysstat-based sar
40 _notrun "sar not from sysstat package"
42 esac
46 status=1 # failure is the default!
47 $sudo rm -rf $tmp.* $seq.full
48 trap "cd $here; rm -rf $tmp.*; exit \$status" 0 1 2 3 15
50 extract_iostat()
52 echo "== Raw iostat:" >> $seq.full
53 cat $1 >> $seq.full
55 f="$2.unsorted"
56 $PCP_AWK_PROG < $1 '
57 BEGIN { cpucount=0; devcount=0; s=1.0 }
58 /Blk_read/ { s=0.5 }
59 /kB_read/ { s=1.0 }
60 /MB_read/ { s=1024 }
61 /^avg-cpu:/ { cpumode=1; cpucount++; next }
62 /^Device: *tps/ { tpsmode=1; devcount++; next }
63 /^Device:/ { devices=1; devcount++; next }
64 /^$/ { cpumode=0; tpsmode=0; devices=0; next }
65 { #print name-prefixed, and name-sorted output
66 if (cpumode == 1 && cpucount > 1) {
67 sample="'$f.'"cpucount-1
68 printf "cpu.user %f\n", $1/100.0 >> sample
69 printf "cpu.nice %f\n", $2/100.0 >> sample
70 printf "cpu.sys %f\n", $3/100.0 >> sample
71 printf "cpu.wait.total %f\n", $4/100.0 >> sample
72 printf "cpu.steal %f\n", $5/100.0 >> sample
73 printf "cpu.idle %f\n", $6/100.0 >> sample
75 if (tpsmode == 1 && devcount > 1) {
76 sample="'$f.'"devcount-1
77 instance=$1
78 printf "dev.total::%s %f\n", instance, $2 >> sample
79 printf "dev.read_bytes::%s %f\n", instance, $3*s >> sample
80 printf "dev.write_bytes::%s %f\n", instance, $4*s >> sample
82 if (devices == 1 && devcount > 1) {
83 sample="'$f.'"devcount-1
84 instance=$1
85 s=0.5 # size scale - sectors vs kilobytes
86 printf "dev.read_merge::%s %f\n", instance, $2 >> sample
87 printf "dev.write_merge::%s %f\n", instance, $3 >> sample
88 printf "dev.read::%s %f\n", instance, $4 >> sample
89 printf "dev.write::%s %f\n", instance, $5 >> sample
90 printf "dev.read_bytes::%s %f\n", instance, $6*s >> sample
91 printf "dev.write_bytes::%s %f\n", instance, $7*s >> sample
92 printf "dev.avactive::%s %f\n", instance, $10 >> sample
93 if (NF == 14) {
94 printf "dev.read_rawactive::%s %f\n", instance, $11 >> sample
95 printf "dev.write_rawactive::%s %f\n", instance, $12 >> sample
97 } }'
98 for sample in 1 2
100 result=`echo $f.$sample | sed -e 's/.unsorted//g'`
101 sort -u < $f.$sample > $result
103 echo "== Extracted iostat sample $sample" >> $seq.full
104 cat $result >> $seq.full
105 done
108 extract_pcp()
110 archive=$1
112 # extract two samples - just disk and cpu metrics, sorted
113 pminfo -f -O+.0 -a $1 kernel disk > $tmp.pminfo.1
114 pminfo -f -O-.1 -a $1 kernel disk > $tmp.pminfo.2
115 for sample in 1 2
117 echo "== Raw pminfo sample $sample:" >> $seq.full
118 cat $tmp.pminfo.$sample >> $seq.full
120 sed < $tmp.pminfo.$sample \
121 -e 's/^disk.//g' \
122 -e 's/^kernel.all.//g' \
123 -e 's/"//g' -e 's/]//g' | \
124 $PCP_AWK_PROG '
125 /^[a-z]/ { metric=$1; next }
126 /^$/ { metric=""; next }
127 / value / { if (NF > 2) { printf "%s::%s %f\n", metric, $4, $6 }
128 if (NF == 2) { printf "%s %f\n", metric, $2 }
129 }' \
130 | sort -u > $2.$sample
132 echo "== Extracted pcp sample $sample:" >> $seq.full
133 cat $tmp.pcp.values.$sample >> $seq.full
134 done
137 compare_samples()
139 for sample in 1 2
141 paste $1.$sample $2.$sample >$tmp.both
142 echo "== Merged $1.$sample and $2.$sample:" >> $seq.full
143 cat $tmp.both >> $seq.full
145 echo Verifying sample $sample
146 $PCP_AWK_PROG <$tmp.both '
147 $2 != 0 && $4 != 0 {
148 # within 2% is close enough to a match
149 if ($2/$4 > 1.002 || $2/$4 < 0.992)
150 print "[",NR,"] mismatch:",$1,$2,$4
151 next
153 $2 == 0 {
154 # within 0.002 of zero is close enough to a match
155 if ($4 > 0.002)
156 print "[",NR,"] mismatch:",$1,$2,$4
157 next
159 $4 == 0 {
160 # within 0.002 of zero is close enough to a match
161 if ($2 > 0.002)
162 print "[",NR,"] mismatch:",$1,$2,$4
163 next
165 done
168 # real QA test starts here
169 export S_TIME_FORMAT=ISO
171 # three samples, one second apart (ignore first though)
172 iostat -t 1 3 > $tmp.iostat
173 extract_iostat $tmp.iostat $tmp.iostat.values
175 echo "== Run iostat2pcp:" >> $seq.full
176 iostat2pcp -v $tmp.iostat $tmp.iostat2pcp >> $seq.full
177 extract_pcp $tmp.iostat2pcp $tmp.pcp.values
179 echo "Comparing stock iostat output to PCP archive"
180 compare_samples $tmp.iostat.values $tmp.pcp.values
182 # compare the extended device stats next
183 iostat -x -t 1 3 > $tmp.iostatx
184 extract_iostat $tmp.iostatx $tmp.iostatx.values
186 iostat2pcp $tmp.iostatx $tmp.iostatx2pcp
187 extract_pcp $tmp.iostatx2pcp $tmp.pcpx.values
189 echo "Comparing extended iostat output to PCP archive"
190 compare_samples $tmp.iostatx.values $tmp.pcpx.values
192 # success, all done
193 status=0
194 exit