3 # Install/Remove postgresql PMDA and check some basic metrics
5 # Copyright (c) 2015 Ken McDonell. All Rights Reserved.
9 echo "QA output created by $seq"
11 # get standard environment, filters and checks
16 [ -d $PCP_PMDAS_DIR/postgresql
] || _notrun
"postgresql PMDA directory is not installed"
18 echo '\q' |
$sudo -u postgres psql
>/dev
/null
2>&1
19 [ $?
-eq 0 ] || _notrun
"Cannot run psql as the postgres user, postgresql not installed or running?"
21 status
=1 # failure is the default!
22 $sudo rm -rf $tmp.
* $seq.full
23 trap "cd $here; rm -rf $tmp.*; exit \$status" 0 1 2 3 15
25 pmdapostgresql_remove
()
27 echo |
tee -a $here/$seq.full
28 echo "=== remove postgresql agent ===" |
tee -a $here/$seq.full
29 $sudo .
/Remove
>$tmp.out
2>&1
30 cat $tmp.out
>>$here/$seq.full
31 _filter_pmda_remove
<$tmp.out
34 pmdapostgresql_install
()
36 # start from known starting points
37 cd $PCP_PMDAS_DIR/postgresql
38 $sudo .
/Remove
>/dev
/null
2>&1
39 $sudo $PCP_RC_DIR/pmcd stop
2>&1 | _filter_pcp_stop
41 echo |
tee -a $here/$seq.full
42 echo "=== postgresql agent installation ===" |
tee -a $here/$seq.full
43 $sudo .
/Install
</dev
/null
>$tmp.out
2>&1
44 cat $tmp.out
>>$here/$seq.full
45 # filter lines like ...
46 # Check postgresql metrics have appeared ... 4 warnings, 208 metrics and 6839 values
48 # Check postgresql metrics have appeared ... X metrics and Y values
49 _filter_pmda_install
<$tmp.out \
51 -e '/^Waiting for pmcd/s/\.\.\.[. ]*$/DOTS/' \
52 -e 's/[0-9][0-9]* warnings, //' \
54 /Check postgresql metrics have appeared/ { if ($7 >= 200) $7 = "X"
55 if ($10 >= 5000) $10 = "Y"
60 _prepare_pmda postgresql
61 trap "_cleanup_pmda postgresql; exit \$status" 0 1 2 3 15
66 $sudo -u postgres psql
-c "$*" >$tmp.out
2>$tmp.err
71 echo "Warning: stderr from psql"
75 echo "Error: psql exit status: $_sts"
78 cat $tmp.out
>>$here/$seq.full
83 -e '/^([0-9][0-9]* row/d' \
84 |
$PCP_AWK_PROG -F\|
'
85 NR == 1 { for (i = 1; i <= NF; i++) name[i] = $i }
86 NR >= 3 { for (i = 1; i <= NF; i++) print NR "|" name[i] "|" $i }'
89 # aim is to match values ... the sql values are lines like
93 # and the pminfo values are in lines like this in $tmp.pcp
94 # postgresql.stat.activity.client_port 3 -1 1 4
96 # Usage: _match dbpattern [[pcppattern|-] [width [fuzz]]]
98 # if pcppattern is missing or "-", use dbpattern
99 # if width specified use only the first n characters of each value
100 # if width is missing or "-", use 0 (match full field width)
101 # the optional fuzz specifies a +/- % tolerance that is allowed
103 # "match" is weakly defined as some value that is not "" and not 0
104 # and that occurs in both sets of values (non determinism in the
105 # queries being run on the DB engine dictate this as close as we can
106 # get ... major PMDA botches fail even this weak test!)
110 rm -f $tmp.match
$tmp.nomatch
112 egrep "\\|$pat\\|" $tmp.db
>$tmp.val.db
113 if [ ! -s $tmp.val.db
]
115 echo "_match: failed to pick any values from DB using pattern \"|$pat|\""
118 [ "$2" != "-" -a -n "$2" ] && pat
="$2"
119 width
=0 # use full field width
120 [ "$3" != "-" -a -n "$3" ] && width
="$3"
122 [ -n "$4" ] && fuzz
="$4"
123 grep "\\.$pat " $tmp.pcp
>$tmp.val.pcp
124 if [ ! -s $tmp.val.pcp
]
126 echo "_match: failed to pick any values from PCP using pattern \"\\.$pat \""
129 nlines
=`wc -l <$tmp.val.pcp | sed -e 's/ //g'`
130 if [ "$nlines" != 1 ]
132 echo "_match: picked $nlines lines of values from PCP, not 1 as expected"
135 # pmprobe output is a bit tricky ... string values have enclosing "
136 if grep '"' $tmp.val.pcp
>/dev
/null
143 $PCP_AWK_PROG <$tmp.val.pcp
'
144 { for (i = 3; i <= NF; i++) {
145 if (i > 3) printf "|"
152 ( echo "$width|$fuzz" ; cat $tmp.tmp
$tmp.val.db
) \
153 |
$PCP_AWK_PROG -F\|
'
154 NR == 1 { # options: field_width fuzz_pct
159 NR == 2 { # PCP values
161 for (i = 1; i <= NF; i++) {
162 if ($i == 0 || $i == "")
167 pcp[j] = substr($i, 1, width)
168 #debug# print "pcp[" j "]=\"" pcp[j] "\""
174 { if ($3 == 0 || $3 == "") next
176 $3 = substr($3, 1, width)
177 for (j = 0; j < npcp; j++) {
178 #debug# print "pcp[" j "]=\"" pcp[j] "\" : db=\"" $3 "\""
180 print "$3" >"'$tmp.match
'"
184 print "pcp[" j "]=\"" pcp[j] "\" : db=\"" $3 "\"" >"'$tmp.nomatch
'"
193 echo "$1: no match" |
tee -a $here/$seq.full
194 [ -f $tmp.nomatch
] && cat $tmp.nomatch
>>$here/$seq.full
199 # real QA test starts here
200 pmdapostgresql_install
203 echo "=== check values with pmie ==="
204 cat <<End-of-File | pmie -t 2sec -T 5sec 2>$tmp.err >$tmp.out
205 // metrics chosen almost at random .. sort of 1 per cluster and
206 // metrics where at least one instance is expected to have a
211 postgresql.active.xlog_current_location_offset > 0
212 -> print "postgresql.active.xlog_current_location_offset: OK"
214 postgresql.active.xlog_current_location_offset <= 0
215 -> print "postgresql.active.xlog_current_location_offset: BAD" " %v"
219 sum_inst instant(postgresql.statio.sys_tables.idx_blks_read) > 0
220 -> print "postgresql.statio.sys_tables.idx_blks_read: OK"
222 -> print "postgresql.statio.sys_tables.idx_blks_read: BAD" & shell "pminfo -f postgresql.statio.sys_tables.idx_blks_read >>$tmp.bad"
226 sum_inst instant(postgresql.statio.sys_indexes.idx_blks_hit) > 0
227 -> print "postgresql.statio.sys_indexes.idx_blks_hit: OK"
229 -> print "postgresql.statio.sys_indexes.idx_blks_hit: BAD" & shell "pminfo -f postgresql.statio.sys_indexes.idx_blks_hit >>$tmp.bad"
233 postgresql.stat.activity.datid > 0
234 -> print "postgresql.stat.activity.datid: OK"
236 postgresql.stat.activity.datid <= 0
237 -> print "postgresql.stat.activity.datid: BAD" " %v"
241 sum_inst instant(postgresql.stat.sys_indexes.idx_scan) > 0
242 -> print "postgresql.stat.sys_indexes.idx_scan: OK"
244 -> print "postgresql.stat.sys_indexes.idx_scan: BAD" & shell "pminfo -f postgresql.stat.sys_indexes.idx_scan >>$tmp.bad"
248 sum_inst instant(postgresql.stat.database.tup_returned) > 0
249 -> print "postgresql.stat.database.tup_returned: OK"
251 -> print "postgresql.stat.database.tup_returned: BAD" & shell "pminfo -f postgresql.stat.database.tup_returned >>$tmp.bad"
255 sum_inst instant(postgresql.stat.sys_tables.idx_tup_fetch) > 0
256 -> print "postgresql.stat.sys_tables.idx_tup_fetch: OK"
258 -> print "postgresql.stat.sys_tables.idx_tup_fetch: BAD" & shell "pminfo -f postgresql.stat.sys_tables.idx_tup_fetch >>$tmp.bad"
262 sum_inst instant(postgresql.stat.xact.all_tables.seq_scan) > 0
263 -> print "postgresql.stat.xact.all_tables.seq_scan: OK"
265 -> print "postgresql.stat.xact.all_tables.seq_scan: BAD" & shell "pminfo -f postgresql.stat.xact.all_tables.seq_scan >>$tmp.bad"
269 sum_inst instant(postgresql.stat.xact.sys_tables.idx_scan) > 0
270 -> print "postgresql.stat.xact.sys_tables.idx_scan: OK"
272 -> print "postgresql.stat.xact.sys_tables.idx_scan: BAD" & shell "pminfo -f postgresql.stat.xact.sys_tables.idx_scan >>$tmp.bad"
276 sum_inst instant(postgresql.stat.all_tables.idx_tup_fetch) > 0
277 -> print "postgresql.stat.all_tables.idx_tup_fetch: OK"
279 -> print "postgresql.stat.all_tables.idx_tup_fetch: BAD" & shell "pminfo -f postgresql.stat.all_tables.idx_tup_fetch >>$tmp.bad"
283 sum_inst instant(postgresql.stat.all_indexes.idx_tup_read) > 0
284 -> print "postgresql.stat.all_indexes.idx_tup_read: OK"
286 -> print "postgresql.stat.all_indexes.idx_tup_read: BAD" & shell "pminfo -f postgresql.stat.all_indexes.idx_tup_read >>$tmp.bad"
291 cat $tmp.out
>>$here/$seq.full
292 cat $tmp.err
>>$here/$seq.full
293 _filter_pmie_log
<$tmp.out \
294 | LC_COLLATE
=POSIX
sort \
296 [ -f $tmp.bad
] && cat $tmp.bad
298 echo "validate values ..."
300 echo |
tee -a $here/$seq.full
301 echo "=== pg_stat_activity ===" |
tee -a $here/$seq.full
302 _do_sql
'select * from pg_stat_activity' >$tmp.db
303 pmprobe
-v postgresql.stat.activity
>$tmp.pcp
304 echo "--- DB values ---" >>$here/$seq.full
305 cat $tmp.db
>>$here/$seq.full
306 echo "--- PCP values ---" >>$here/$seq.full
307 cat $tmp.pcp
>>$here/$seq.full
310 _match
"(current_query|query)" current_query
312 echo |
tee -a $here/$seq.full
313 echo "=== pg_stat_bgwriter ===" |
tee -a $here/$seq.full
314 _do_sql
'select * from pg_stat_bgwriter' >$tmp.db
315 pmprobe
-v postgresql.stat.bgwriter
>$tmp.pcp
316 echo "--- DB values ---" >>$here/$seq.full
317 cat $tmp.db
>>$here/$seq.full
318 echo "--- PCP values ---" >>$here/$seq.full
319 cat $tmp.pcp
>>$here/$seq.full
320 _match checkpoints_timed
323 echo |
tee -a $here/$seq.full
324 echo "=== pg_stat_database ===" |
tee -a $here/$seq.full
325 _do_sql
'select * from pg_stat_database' >$tmp.db
326 pmprobe
-v postgresql.stat.database
>$tmp.pcp
327 echo "--- DB values ---" >>$here/$seq.full
328 cat $tmp.db
>>$here/$seq.full
329 echo "--- PCP values ---" >>$here/$seq.full
330 cat $tmp.pcp
>>$here/$seq.full
331 _match stats_reset
- 10
332 _match tup_fetched
- - 25
334 echo |
tee -a $here/$seq.full
335 echo "=== pg_stat_all_tables ===" |
tee -a $here/$seq.full
336 _do_sql
'select * from pg_stat_all_tables' >$tmp.db
337 pmprobe
-v postgresql.stat.all_tables
>$tmp.pcp
338 echo "--- DB values ---" >>$here/$seq.full
339 cat $tmp.db
>>$here/$seq.full
340 echo "--- PCP values ---" >>$here/$seq.full
341 cat $tmp.pcp
>>$here/$seq.full
347 echo |
tee -a $here/$seq.full
348 echo "=== pg_stat_sys_tables ===" |
tee -a $here/$seq.full
349 _do_sql
'select * from pg_stat_sys_tables' >$tmp.db
350 pmprobe
-v postgresql.stat.sys_tables
>$tmp.pcp
351 echo "--- DB values ---" >>$here/$seq.full
352 cat $tmp.db
>>$here/$seq.full
353 echo "--- PCP values ---" >>$here/$seq.full
354 cat $tmp.pcp
>>$here/$seq.full
360 echo |
tee -a $here/$seq.full
361 echo "=== pg_stat_all_indexes ===" |
tee -a $here/$seq.full
362 _do_sql
'select * from pg_stat_all_indexes' >$tmp.db
363 pmprobe
-v postgresql.stat.all_indexes
>$tmp.pcp
364 echo "--- DB values ---" >>$here/$seq.full
365 cat $tmp.db
>>$here/$seq.full
366 echo "--- PCP values ---" >>$here/$seq.full
367 cat $tmp.pcp
>>$here/$seq.full
373 echo |
tee -a $here/$seq.full
374 echo "=== pg_stat_sys_indexes ===" |
tee -a $here/$seq.full
375 _do_sql
'select * from pg_stat_sys_indexes' >$tmp.db
376 pmprobe
-v postgresql.stat.sys_indexes
>$tmp.pcp
377 echo "--- DB values ---" >>$here/$seq.full
378 cat $tmp.db
>>$here/$seq.full
379 echo "--- PCP values ---" >>$here/$seq.full
380 cat $tmp.pcp
>>$here/$seq.full
386 echo "PMDA log file ..." >>$here/$seq.full
387 $sudo cat $PCP_LOG_DIR/pmcd
/postgresql.log
>>$here/$seq.full
389 pmdapostgresql_remove