pmrep: fix archive end time reporting
[pcp.git] / qa / 216
blob161be1d69b1b9279e3da1b447640addfd7fe3276
1 #! /bin/sh
2 # PCP QA Test No. 216
4 # Verify network.<protocol> statistics
5 # (Linux version, see 117 for non-Linux version - although this version
6 # has been completely re-written to deal with optional output from the
7 # Linux version of netstat)
9 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
10 # Copyright (c) 2009 Ken McDonell. All Rights Reserved.
13 seq=`basename $0`
14 echo "QA output created by $seq"
16 # get standard environment, filters and checks
17 . ./common.product
18 . ./common.filter
19 . ./common.check
21 which netstat >/dev/null 2>&1 || _notrun "netstat not installed"
23 if [ $PCP_PLATFORM != linux ]
24 then
25 echo "network.* checks for non-linux done in test 117" >$seq.notrun
26 echo "$seq: [not run] `cat $seq.notrun`"
27 exit 0
30 #debug# tmp=`pwd`/tmp
31 compare=`pwd`/src/compare
32 status=0 # success is the default!
33 $sudo rm -rf $tmp.*
34 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
36 if [ ! -x $compare ]
37 then
38 echo "Can't find compare, giving up"
39 exit 1
42 if pminfo network.ip >/dev/null
43 then
45 else
46 echo "pminfo network.ip not working, giving up"
47 exit 1
50 ns1=$tmp.netstat1
51 pcp=$tmp.pcp
52 ns2=$tmp.netstat2
54 rm -f $seq.full
55 rm -rf $ns1 $pcp $ns2
57 cat <<'End-of-File' >$tmp.map
58 # build by hand from the source file statistics.c used to make netstat
59 # tags ...
60 # #notreported# netstat -s does not report this
61 # #notcounter# semantics is not counter, so not suitable for this test
63 # SNMP Name|netstat string|PCP name
64 # Iptab[]
65 #notreported#Forwarding|Forwarding is %s|network.ip.forwarding
66 #notreported#DefaultTTL|Default TTL is NNN|network.ip.defaultttl
67 InReceives|NNN total packets received|network.ip.inreceives
68 InHdrErrors|NNN with invalid headers|network.ip.inhdrerrors
69 InAddrErrors|NNN with invalid addresses|network.ip.inaddrerrors
70 ForwDatagrams|NNN forwarded|network.ip.forwdatagrams
71 InUnknownProtos|NNN with unknown protocol|network.ip.inunknownprotos
72 InDiscards|NNN incoming packets discarded|network.ip.indiscards
73 InDelivers|NNN incoming packets delivered|network.ip.indelivers
74 OutRequests|NNN requests sent out|network.ip.outrequests
75 OutDiscards|NNN outgoing packets dropped|network.ip.outdiscards
76 OutNoRoutes|NNN dropped because of missing route|network.ip.outnoroutes
77 ReasmTimeout|NNN fragments dropped after timeout|network.ip.reasmtimeout
78 ReasmReqds|NNN reassemblies required|network.ip.reasmreqds
79 ReasmOKs|NNN packets reassembled ok|network.ip.reasmoks
80 ReasmFails|NNN packet reassembles failed|network.ip.reasmfails
81 FragOKs|NNN fragments received ok|network.ip.fragoks
82 FragFails|NNN fragments failed|network.ip.fragfails
83 FragCreates|NNN fragments created|network.ip.fragcreates
84 # Icmptab[]
85 InMsgs|NNN ICMP messages received|network.icmp.inmsgs
86 InErrors|NNN input ICMP message failed.|network.icmp.inerrors
87 InDestUnreachs|ICMP input *destination unreachable: NNN|network.icmp.indestunreachs
88 InTimeExcds|ICMP input *timeout in transit: NNN|network.icmp.intimeexcds
89 nParmProbs|ICMP input *wrong parameters: NNN|network.icmp.inparmprobs
90 InSrcQuenchs|ICMP input *source quenches: NNN|network.icmp.insrcquenchs
91 InRedirects|ICMP input *redirects: NNN|network.icmp.inredirects
92 InEchos|ICMP input *echo requests: NNN|network.icmp.inechos
93 InEchoReps|ICMP input *echo replies: NNN|network.icmp.inechoreps
94 InTimestamps|ICMP input *timestamp request: NNN|network.icmp.intimestamps
95 InTimestampReps|ICMP input *timestamp reply: NNN|network.icmp.intimestampreps
96 InAddrMasks|ICMP input *address mask request: NNN|network.icmp.inaddrmasks
97 InAddrMaskReps|ICMP input *address mask replies: NNN|network.icmp.inaddrmaskreps
98 OutMsgs|NNN ICMP messages sent|network.icmp.outmsgs
99 OutErrors|NNN ICMP messages failed|network.icmp.outerrors
100 OutDestUnreachs|ICMP output *destination unreachable: NNN|network.icmp.outdestunreachs
101 OutTimeExcds|ICMP output *time exceeded: NNN|network.icmp.outtimeexcds
102 OutParmProbs|ICMP output *wrong parameters: NNN|network.icmp.outparmprobs
103 OutSrcQuenchs|ICMP output *source quench: NNN|network.icmp.outsrcquenchs
104 OutRedirects|ICMP output *redirect: NNN|network.icmp.outredirects
105 OutEchos|ICMP output *echo request: NNN|network.icmp.outechos
106 OutEchoReps|ICMP output *echo replies: NNN|network.icmp.outechoreps
107 OutTimestamps|ICMP output *timestamp requests: NNN|network.icmp.outtimestamps
108 OutTimestampReps|ICMP output *timestamp replies: NNN|network.icmp.outtimestampreps
109 OutAddrMasks|ICMP output *address mask requests: NNN|network.icmp.outaddrmasks
110 OutAddrMaskReps|ICMP output *address mask replies: NNN|network.icmp.outaddrmaskreps
111 # Tcptab[]
112 #notreported#RtoAlgorithm|RTO algorithm is %s|network.tcp.rtoalgorithm
113 #notreported#RtoMin||network.tcp.rtomin
114 #notreported#RtoMax||network.tcp.rtomax
115 #notreported#MaxConn||network.tcp.maxconn
116 #notcounter#ActiveOpens|NNN active connections openings|network.tcp.activeopens
117 #notcounter#PassiveOpens|NNN passive connection openings|network.tcp.passiveopens
118 AttemptFails|NNN failed connection attempts|network.tcp.attemptfails
119 EstabResets|NNN connection resets received|network.tcp.estabresets
120 #notcounter#CurrEstab|NNN connections established|network.tcp.currestab
121 InSegs|NNN segments received|network.tcp.insegs
122 OutSegs|NNN segments send out|network.tcp.outsegs
123 RetransSegs|NNN segments retransmited|network.tcp.retranssegs
124 InErrs|NNN bad segments received.|network.tcp.inerrs
125 OutRsts|NNN resets sent|network.tcp.outrsts
126 # Udptab[]
127 InDatagrams|NNN packets received|network.udp.indatagrams
128 NoPorts|NNN packets to unknown port received.|network.udp.noports
129 InErrors|NNN packet receive errors|network.udp.inerrors
130 OutDatagrams|NNN packets sent|network.udp.outdatagrams
131 #notreported#RcvbufErrors||network.udp.recvbuferrors
132 #notreported#SndbufErrors||network.udp.sndbuferrors
133 End-of-File
135 # real QA test starts here
137 _get_netstat()
139 netstat -s \
140 | tee -a $seq.full \
141 | $PCP_AWK_PROG >$tmp.out '
142 /ICMP input histogram:/ { pfx = "ICMP input"; next }
143 /ICMP output histogram:/ { pfx = "ICMP output"; next }
144 /^Ip:/ { pfx = ""; skip = 0; print; next }
145 /^Icmp:/ { pfx = ""; skip = 0; print; next }
146 /^Tcp:/ { pfx = ""; skip = 0; print; next }
147 /^Udp:/ { pfx = ""; skip = 0; print; next }
148 /^[A-Z]/ { pfx = ""; skip = 1; print $0,"... skipped"; next }
149 skip == 1 { next }
150 /:/ { print pfx,$0; next }
151 { pfx = ""; print }'
152 echo "--- Culled netstat ---" >>$seq.full
153 cat $tmp.out >>$seq.full
154 $PCP_AWK_PROG <$tmp.map -F\| '
155 /^#/ { next }
156 { print $2 }' \
157 | sed -e 's/NNN/\\\\([0-9][0-9]*\\\\)/' \
158 | while read pat
160 echo "pat=$pat" >>$seq.full
161 sed -n -e 's/^[ ]*//' -e "/$pat/s//\\1/p" <$tmp.out >$tmp.tmp
162 if [ -s $tmp.tmp ]
163 then
164 cat $tmp.tmp
165 else
166 # assume it is marked opt_number in the statistics table, so
167 # netstat does not generate output if the value is zero
168 echo "0"
170 done
173 echo "=== First netstat ===" >>$seq.full
174 _get_netstat >$ns1
175 echo "=== Filtered first netstat ===" >>$seq.full
176 cat $ns1 >>$seq.full
178 echo "=== pmprobe ===" >>$seq.full
179 $PCP_AWK_PROG <$tmp.map -F\| '
180 /^#/ { next }
181 { print $3 }' \
182 | tee $tmp.metrics \
183 | while read metric
185 pmprobe -v "$metric" 2>&1
186 done \
187 | tee -a $seq.full \
188 | while read metric sts val
190 if [ "$sts" = 1 ]
191 then
192 echo "$val"
193 else
194 # would prefer -1, but that messes up src/compare and 0
195 # happens too often ... 42424242 has only a 1 in 2^31 chance
196 # of hitting a false match!
197 echo "42424242"
199 done >$pcp
201 echo "=== Second netstat ===" >>$seq.full
202 _get_netstat >$ns2
203 echo "=== Filtered second netstat ===" >>$seq.full
204 cat $ns2 >>$seq.full
206 nm=`wc -l <$pcp | sed -e 's/[ ]*//g'`
207 nn=`wc -l <$ns2 | sed -e 's/[ ]*//g'`
208 if [ $nm -lt $nn ]
209 then
210 echo "Update list! fewer metrics ($nm) than netstat statistics ($nn) -- see $seq.full"
211 elif [ $nm -gt $nn ]
212 then
213 echo "Update list! more metrics ($nm) than netstat statistics ($nn) -- see $seq.full"
216 echo "#!/bin/sh" >>$tmp.sh
217 echo "sts=0" >>$tmp.sh
218 paste -d" \n" $ns1 $pcp $ns2 $tmp.metrics \
219 | $PCP_AWK_PROG '
220 NF == 4 {
221 printf "if '$compare' %d %d %d; then :; else ", $1, $2, $3;
222 printf "sts=1; echo \"%s = %d out of range %d..%d\"; fi\n", $4, $2, $1, $3
223 next
226 print "echo \"Test botch:",$0,"\""
227 next
228 }' \
229 >>$tmp.sh
230 echo "exit $sts" >>$tmp.sh
231 chmod u+x $tmp.sh
233 cat $tmp.sh >>$seq.full
235 # for debugging
236 # if sh -x $tmp.sh
238 if sh $tmp.sh
239 then
240 exit 0
241 else
242 echo "Bad network.* metrics"
243 exit 1