Merge branch 'master' of git://git.pcp.io/pcp into qt
[pcp.git] / qa / 835
blob51e8876cc5e88e39b15acdc2920dfb18b233f689
1 #!/bin/sh
2 # PCP QA Test No. 835
3 # Exercise the memcache PMDA - install, remove and values.
5 # Copyright (c) 2014-2015 Red Hat.
6 # Copyright (c) 2014 Ken McDonell. All Rights Reserved.
7 # Copyright (c) 2008 Aconex. All Rights Reserved. (based on qa/348)
10 seq=`basename $0`
11 echo "QA output created by $seq"
13 # get standard environment, filters and checks
14 . ./common.product
15 . ./common.filter
16 . ./common.check
18 [ -d $PCP_PMDAS_DIR/memcache ] || _notrun "memcache PMDA directory is not installed"
20 port=11211
21 $PCP_BINADM_DIR/telnet-probe -c localhost $port || \
22 _notrun "Noones home on the default memcached port $port"
24 status=1 # failure is the default!
25 $sudo rm -rf $tmp.* $seq.full
27 pmdamemcache_remove()
29 echo
30 echo "=== remove memcache agent ==="
31 $sudo ./Remove >$tmp.out 2>&1
32 _filter_pmda_remove <$tmp.out
35 pmdamemcache_install()
37 # start from known starting points
38 cd $PCP_PMDAS_DIR/memcache
39 $sudo ./Remove >/dev/null 2>&1
40 $sudo $PCP_RC_DIR/pmcd stop
42 cat <<EOF >$tmp.config
43 \$memcache_delay = 1;
44 @memcache_instances = ( 0 => '127.0.0.1:11211' );
45 EOF
46 echo "pmdamemcache config:" >> $here/$seq.full
47 cat $tmp.config >> $here/$seq.full
49 [ -f $PCP_PMDAS_DIR/memcache/memcache.conf ] && \
50 $sudo cp $PCP_PMDAS_DIR/memcache/memcache.conf $tmp.backup
51 $sudo cp $tmp.config $PCP_PMDAS_DIR/memcache/memcache.conf
53 echo
54 echo "=== memcache agent installation ==="
55 $sudo ./Install </dev/null >$tmp.out 2>&1
56 # Check metrics have appeared ... X metrics and Y values
57 _filter_pmda_install <$tmp.out \
58 | sed \
59 -e '/^Waiting for pmcd/s/\.\.\.[. ]*$/DOTS/' \
60 | $PCP_AWK_PROG '
61 /Check memcache metrics have appeared/ { if ($7 >= 16 && $7 <= 50) $7 = "X"
62 if ($10 >= 16 && $10 <= 50) $10 = "Y"
64 { print }'
67 pmdamemcache_cleanup()
69 if [ -f $tmp.backup ]; then
70 $sudo cp $tmp.backup $PCP_PMDAS_DIR/memcache/memcache.conf
71 $sudo rm $tmp.backup
72 else
73 $sudo rm -f $PCP_PMDAS_DIR/memcache/memcache.conf
75 _cleanup_pmda memcache
78 _prepare_pmda memcache
79 trap "pmdamemcache_cleanup; exit \$status" 0 1 2 3 15
81 # make pmprobe output comparable to memcachestats
82 rewrite_memcache_metric_names()
84 sed \
85 -e 's/^memcache.//g' \
86 -e 's/^gets /cmd_get /g' \
87 -e 's/^sets /cmd_set /g' \
88 -e 's/^hits /get_hits /g' \
89 -e 's/^misses /get_misses /g' \
90 -e 's/^current_items/curr_items/g' \
91 -e 's/^current_connections/curr_connections/g' \
92 #end#
95 # real QA test starts here
96 pmdamemcache_install
98 echo
99 echo "=== extract metric values ==="
100 pmprobe -v memcache \
101 | rewrite_memcache_metric_names \
102 | LC_COLLATE=POSIX sort >$tmp.probe
103 echo "from pmprobe ..." >>$here/$seq.full
105 $here/src/memcachestats.pl \
106 | sed -e 's/ / 1 /' \
107 | LC_COLLATE=POSIX sort >$tmp.values
108 echo "from src/memcachestats.pl ..." >>$here/$seq.full
110 cat $tmp.values >>$here/$seq.full
111 LC_COLLATE=POSIX join $tmp.probe $tmp.values >$tmp.all
112 echo >>$here/$seq.full
113 cat $tmp.all >>$here/$seq.full
115 echo
116 echo "=== check values ==="
117 cat $tmp.all \
118 | while read metric n1 vpcp n2 vmemcache
120 if [ "$n1" = 1 -a "$n2" = 1 ]
121 then
122 case $metric
124 bytes_read|bytes_written)
125 # unstable, skip these ones
127 curr_connections|connection_structures)
128 # +/- 2
129 _within_tolerance $metric $vpcp $vmemcache 2 -v
131 total_connections)
132 # +/- 5
133 _within_tolerance $metric $vpcp $vmemcache 5 -v
136 # +/- 10%
137 _within_tolerance $metric $vpcp $vmemcache 10% -v
139 esac
140 else
141 echo "$metric: number of values not 1 as expected: pcp $n1 / memcache $n2"
143 done | tee -a $here/$seq.full
145 pmdamemcache_remove
146 status=0
147 exit