3 # Copyright (c) 2014 Red Hat.
4 # Copyright (c) 2008-2010 Aconex. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # Compare two PCP archives and report significant differences
19 # Get standard environment
20 .
$PCP_DIR/etc
/pcp.env
22 tmp
=`mktemp -d /var/tmp/pcp.XXXXXXXXX` ||
exit 1
24 trap "rm -rf $tmp; exit \$status" 0 1 2 3 15
27 cat > $tmp/usage
<< EOF
28 # Usage: [options] archive1 [archive2]
31 -d,--keep debug, keep intermediate files
32 -p=N,--precision=N number of digits to display after the decimal point
33 -q=N,--threshold=N change interesting threshold to be > N or < 1/N [N=2]
34 --skip-missing do not report metrics missing between the archives
35 --skip-excluded do not report the list of metrics being excluded
38 -B=TIME,--begin=TIME start time for second archive (optional)
39 -E=TIME,--end=TIME end time for second archive (optional)
40 -x=REGEX egrep(1) pattern of metric(s) to be excluded
41 -X=FILE file containing egrep(1) patterns to exclude
49 pmgetopt
--usage --progname=$prog --config=$tmp/usage
53 # filter the pmlogsummary output getting ready for join(1) ...
54 # - add | field separator between metric name and value
55 # - dodge chatter about metrics with insufficient data
56 # - dodge chatter from -z
57 # - exclude metrics we don't want
63 -e 's/ *\([0-9][0-9.]*\)\([^"]*\)$/|\1/' \
64 -e '/^\*.* - insufficient archive data.$/'d \
65 -e '/^Note: timezone set to local timezone of host/d' \
67 |
egrep -v -f $tmp/exclude \
68 |
sort -t\|
-k 1,1 -k 2
71 cat <<'End-of-File' >$tmp/exclude
85 ARGS
=`pmgetopt --progname=$prog --config=$tmp/usage -- "$@"`
93 -d) trap "exit \$status" 0 1 2 3 15
96 [ -d "$tmp" ] || mkdir
"$tmp" ||
exit 1
97 mv $otmp/exclude
$tmp/exclude
102 opts
="$opts -p $precision"
119 -x) echo "$2" >>$tmp/exclude
122 -X) cat "$2" >>$tmp/exclude
127 -Z) opts
="$opts -Z $2"
146 if [ $# -lt 1 -o $# -gt 2 ]
159 [ $precision -lt 3 -o $precision -gt 15 ] && precision
=3
160 colwidth
=`expr 12 + $precision`
162 echo "Directory: `pwd`"
165 echo "Excluded metrics:"
166 sed -e 's/^/ /' <$tmp/exclude
171 if [ "X$start1" != X
]; then
172 options
="$options -S $start1"
174 if [ "X$finish1" != X
]; then
175 options
="$options -T $finish1"
177 pmlogsummary
-N $options $arch1 2>$tmp/err | _fix
>$tmp/1
180 echo "Warnings from pmlogsummary ... $arch1"
186 if [ "X$start2" != X
]; then
187 options
="$options -S $start2"
188 elif [ "X$start1" != X
]; then
189 options
="$options -S $start1"
191 if [ "X$finish2" != X
]; then
192 options
="$options -T $finish2"
193 elif [ "X$finish1" != X
]; then
194 options
="$options -T $finish1"
196 pmlogsummary
-N $options $arch2 2>$tmp/err | _fix
>$tmp/2
199 echo "Warnings from pmlogsummary ... $arch2"
212 window1
="$window1-end"
214 window1
="$window1-$finish1"
224 window2
="$window2-end"
226 window2
="$window2-$finish2"
231 join -t\|
-v 2 $tmp/1 $tmp/2 >$tmp/tmp
234 echo "Missing from $arch1 $window1 (not compared) ..."
235 sed <$tmp/tmp
-e 's/|.*//' -e 's/^/ /'
239 join -t\|
-v 1 $tmp/1 $tmp/2 >$tmp/tmp
242 echo "Missing from $arch2 $window2 (not compared) ..."
243 sed <$tmp/tmp
-e 's/|.*//' -e 's/^/ /'
248 a1
=`basename "$arch1"`
249 a2
=`basename "$arch2"`
250 echo "$thres" |
awk '
251 { printf "Ratio Threshold: >= %.2f or <= %.3f\n",'"$thres"',1/'"$thres"'
252 printf "%*s %*s Ratio Metric-Instance\n",
253 '$colwidth', "'"$a1"'", '$colwidth', "'"$a2"'" }'
262 window1
="$window1-end"
264 window1
="$window1-$finish1"
274 window2
="$window2-end"
276 window2
="$window2-$finish2"
278 printf '%*s %*s\n' $colwidth "$window1" $colwidth "$window2"
279 join -t\|
$tmp/1 $tmp/2 \
283 precision='"$precision"'
286 printf "%*.*f%*s",15+extra,0,v,1," "
288 printf "%*.*f%*s",11,0,v,2+precision," "
290 printf "%*.*f%*s",13+extra,1+extra,v,3," "
292 printf "%*.*f%*s",14+extra,2+extra,v,2," "
294 printf "%*.*f%*s",15+extra,precision,v,1," "
296 $3+0 == 0 || $2+0 == 0 {
308 $2 / $3 >= '"$thres"' || $3 / $2 >= '"$thres"' {
323 | LC_COLLATE
=${LC_COLLATE:-POSIX} sort -k 3,3nr
-k 4 \
324 |
sed -e 's/100+/>100/' -e 's/ 0.001-/<0.001 /' >$tmp/out
326 # sort in ratio order
328 $PCP_AWK_PROG '$3 == "|+|" {print}' <$tmp/out
329 $PCP_AWK_PROG '$3 == ">100" {print}' <$tmp/out
330 $PCP_AWK_PROG '$3 ~/^[0-9]/ {print}' <$tmp/out
331 $PCP_AWK_PROG '$3 == "<0.001" {print}' <$tmp/out
332 $PCP_AWK_PROG '$3 == "|-|" {print}' <$tmp/out