File: common.openmetrics

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (120 lines) | stat: -rw-r--r-- 3,056 bytes parent folder | download
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
113
114
115
116
117
118
119
120
#
# Common shell routines for testing the OpenMetrics PMDA.
#
# Copyright (c) 2017,2019 Red Hat.
#

# get standard environment, filters and checks
. ./common.python

$python -c "import requests" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python requests module not installed"

CONFIG_DIR=$PCP_PMDAS_DIR/openmetrics/config.d

_pmdaopenmetrics_check()
{
    [ -f $PCP_PMDAS_DIR/openmetrics/pmdaopenmetrics.python ] || return 1
    return 0
}

_pmdaopenmetrics_remove()
{
    echo
    echo "=== remove openmetrics agent ===" | tee -a $seq_full
    cd $PCP_PMDAS_DIR/openmetrics
    $sudo ./Remove >$tmp.out 2>&1
    cat $tmp.out >>$seq_full
    _filter_pmda_remove <$tmp.out \
    | $PCP_AWK_PROG '
BEGIN		{ state = 0 }
/ Xferd / || / XXffeerrdd / { state = 1; next }
state == 1 && /^\[/	{ state = 0 }
state == 0	{ print }' \
    | sed \
	-e '/ Info: /d' \
    # end
}

_pmdaopenmetrics_install()
{
    # start from known starting points
    cd $PCP_PMDAS_DIR/openmetrics
    $sudo ./Remove >/dev/null 2>&1
    _service pmcd stop 2>&1 | _filter_pcp_stop

    echo
    echo "=== openmetrics agent installation ==="
    $sudo ./Install </dev/null >$tmp.out 2>&1
    cat $tmp.out >>$seq_full
}

_pmdaopenmetrics_save_config()
{
    $sudo rm -rf $CONFIG_DIR.$seq
    $sudo mv $CONFIG_DIR $CONFIG_DIR.$seq
    $sudo mkdir -p $CONFIG_DIR
    $sudo chmod 777 $CONFIG_DIR
    for __f in $PCP_VAR_DIR/config/pmda/144.*.py; do
	[ -f "$__f" ] && $sudo mv -f $__f $__f.$seq
    done
    # turn off all pmloggers when running open metrics tests
    _stop_auto_restart pmlogger
    _service pmlogger stop 2>&1 | _filter_pcp_stop
}

_pmdaopenmetrics_restore_config()
{
    if [ -d $CONFIG_DIR.$seq ]; then
	$sudo rm -rf $CONFIG_DIR
	$sudo mv $CONFIG_DIR.$seq $CONFIG_DIR
	$sudo chmod 755 $CONFIG_DIR
    fi
    $sudo rm -f $PCP_VAR_DIR/config/pmda/144.*.py
    for __f in $PCP_VAR_DIR/config/pmda/144.*.py.$seq; do
	[ -f "$__f" ] && $sudo mv -f $__f `echo $__f | sed -e "s/\.$seq//"`
    done
}

_pmdaopenmetrics_cleanup()
{
    echo "=== openmetrics PMDA log ===" >>$seq_full
    if [ -f $PCP_LOG_DIR/pmcd/openmetrics.log ]
    then
	cat $PCP_LOG_DIR/pmcd/openmetrics.log >>$seq_full
    else
	echo "Error: PMDA log file is missing" >>$seq_full
    fi

    _pmdaopenmetrics_restore_config
    # note: _restore_auto_restart pmcd done in _cleanup_pmda()
    _cleanup_pmda openmetrics
    # restart all pmloggers after running open metrics tests
    _restore_auto_restart pmlogger
    _service pmlogger restart 2>&1 | _filter_pcp_restart
    _wait_for_pmlogger
}

# wait for the PMDA to dynamically create a named metric (or subtree)
_pmdaopenmetrics_wait_for_metric()
{
    __metric="$1"
    [ -z "$__metric" ] && __metric=openmetrics.control.calls

    # wait for the requested metric to appear in the pmns
    __i=0
    while [ $__i -lt 30 ]
    do
    	if pminfo $__metric >/dev/null 2>&1
	then
	    # all good
	    return 0
	fi
	sleep 1
	__i=`expr $__i + 1`
    done

    # timeout, fail
    echo _pmdaopenmetrics_wait_for_metric FAILED for metric $__metric
    return 1
}