1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#!/bin/sh
# PCP QA Test No. 1976
# Test pmdaopenmetrics metric removal
#
# Copyright (c) 2025 Red Hat. All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard environment, filters and checks
. ./common.openmetrics
_pmdaopenmetrics_check || _notrun "openmetrics pmda not installed"
status=1 # failure is the default!
_cleanup()
{
cd $here
_pmdaopenmetrics_cleanup
$sudo rm -rf $tmp $tmp.*
}
_prepare_pmda openmetrics
trap "_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd
_pmdaopenmetrics_save_config
# add all the sample text files as urls.
# need to be a place the user $PCP_USER (pmcd) can read
#
( cd $here/openmetrics/samples; ls -1 *.txt ) | sort | while read file
do
cp $here/openmetrics/samples/$file $tmp.$file
urlbase=`basename "$file" .txt | tr .- _`
echo 'file://'$tmp.$file >$tmp.tmp
$sudo cp $tmp.tmp $PCP_PMDAS_DIR/openmetrics/config.d/$urlbase.url
done
ls -l $PCP_PMDAS_DIR/openmetrics/config.d >>$seq_full
# add all the sample scripts
cp -a $here/openmetrics/scripts/* $PCP_PMDAS_DIR/openmetrics/config.d
find $PCP_PMDAS_DIR/openmetrics/config.d -name GNU\* -exec rm -f {} ";"
_pmdaopenmetrics_install
iam=openmetrics
# append -R option to pmcd config
sed < $PCP_PMCDCONF_PATH \
-e "/^$iam.*/s/$/ -R 1/" \
> $tmp.conf
$sudo cp $tmp.conf $PCP_PMCDCONF_PATH
if ! _service pmcd restart 2>&1; then _exit 1; fi \
| _filter_pcp_restart
sleep 2
if ! _pmdaopenmetrics_wait_for_metric openmetrics.thermostat
then
status=1
exit
fi
echo "-- metric removal of new source/metric --"
$sudo rm $PCP_PMDAS_DIR/openmetrics/config.d/simple_metric.url
pminfo openmetrics.simple_metric
echo
echo "-- check control metrics disappeared --"
pminfo -dfmt openmetrics.control.status_code
echo
echo "-- source re-addition --"
# same access controls logic as above, user $PCP_USER needs to be
# able to read the file at the end of the URL
#
cp $here/openmetrics/samples/simple_metric.txt $tmp.simple_metric.txt
echo 'file:///'$tmp.simple_metric.txt > $PCP_PMDAS_DIR/openmetrics/config.d/simple_metric.url
pminfo openmetrics.simple_metric
echo
echo "-- check control metrics reappeared --"
pminfo -dfmt openmetrics.control.status_code
echo
echo "-- metric removal of recognized source/metric --"
$sudo rm $PCP_PMDAS_DIR/openmetrics/config.d/simple_metric.url
pminfo openmetrics.simple_metric
echo
echo "-- source re-addition with epoch timestamp --"
cp $here/openmetrics/samples/simple_metric.txt $tmp.simple_metric.txt
echo 'file:///'$tmp.simple_metric.txt > $PCP_PMDAS_DIR/openmetrics/config.d/simple_metric.url
$sudo touch -t 197001010000 $PCP_PMDAS_DIR/openmetrics/config.d/simple_metric.url
pminfo openmetrics.simple_metric
echo
echo "-- metric removal by modifying source file, source persists --"
$sudo sed -i -e "/metric2/d" $tmp'.simple_metric.txt'
echo "-- sleep to allow for old_enough_for_refresh() --"
sleep 2
echo
echo "-- metric2 removed --"
pminfo openmetrics.simple_metric
_pmdaopenmetrics_remove >/dev/null 2>&1
# success, all done
status=0
exit
|