File: 1110

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 (122 lines) | stat: -rwxr-xr-x 3,319 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
121
122
#!/bin/sh
# PCP QA Test No. 1110
# Exercise the HAProxy PMDA - install, remove and values.
#
# Copyright (c) 2017 Red Hat.
#

seq=`basename $0`
echo "QA output created by $seq"

. ./common.python

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

[ -f $PCP_PMDAS_DIR/haproxy/connect ] || _notrun "haproxy PMDA not installed"

# from the PMDA's Install script
eval `$PCP_PYTHON_PROG $PCP_PMDAS_DIR/haproxy/connect --config`
[ -n "$user" ] || _notrun "haproxy PMDA's connect script failed to set \$user"
[ -n "$socket" ] || _notrun "haproxy PMDA's connect script failed to set \$socket"
[ -S "$socket" ] && _notrun "haproxy stats socket already exists; haproxy service running?"

status=1       # failure is the default!
signal=$PCP_BINADM_DIR/pmsignal

# cull these "first time ever run" warnings ...
# [Wed Oct  9 09:07:50] pmdahaproxy(29369) Error: pmdaCacheOp: $PCP_VAR_DIR/config/pmda/145.0: empty file?
#
install_filter()
{
    sed \
	-e '/Error: pmdaCacheOp: .* empty file?/d' \
    # end
}

pmda_filter()
{
    sed \
	-e "s/\[.* or /\[X or /g" \
    #end
}

pmda_remove()
{
    echo
    echo "=== remove haproxy agent ==="
    $sudo ./Remove >$tmp.out 2>&1
    _filter_pmda_remove <$tmp.out
}

pmda_install()
{
    # start from known starting points
    cd $PCP_PMDAS_DIR/haproxy
    $sudo ./Remove >/dev/null 2>&1

    cat <<EOF >$tmp.config
[pmda]
user = $user
socket = $socket
EOF
    echo "pmdahaproxy config:" >> $seq_full
    cat $tmp.config >> $seq_full

    [ -f $PCP_PMDAS_DIR/haproxy/haproxy.conf ] && \
    $sudo cp $PCP_PMDAS_DIR/haproxy/haproxy.conf $tmp.backup
    $sudo cp $tmp.config $PCP_PMDAS_DIR/haproxy/haproxy.conf

    echo
    echo "=== haproxy agent installation ==="
    $sudo ./Install </dev/null >$tmp.out 2>&1
    cat $tmp.out | _filter_pmda_install | install_filter
}

pmda_cleanup()
{
    [ -n "$spid" ] && $sudo $signal -s KILL $spid >/dev/null 2>&1
    $sudo rm -f $socket >/dev/null 2>&1
    if [ -f $tmp.backup ]; then
        $sudo cp $tmp.backup $PCP_PMDAS_DIR/haproxy/haproxy.conf
        $sudo rm $tmp.backup
    else
        $sudo rm -f $PCP_PMDAS_DIR/haproxy/haproxy.conf
    fi
    # note: _restore_auto_restart pmcd done in _cleanup_pmda()
    _cleanup_pmda haproxy
}

_prepare_pmda haproxy
trap "pmda_cleanup; exit \$status" 0 1 2 3 15

_stop_auto_restart pmcd

# real QA test starts here
$sudo mkdir -p $(dirname $socket)
$sudo chmod 0755 $(dirname $socket)
$sudo $python $here/haproxy/haproxy_stats_server.python $socket &
spid=$($sudo $PCP_PS_PROG $PCP_PS_ALL_FLAGS 2>/dev/null \
       | grep '/[p]ython' \
       | $PCP_AWK_PROG '/\/haproxy\// {print $2}'
      )
disown > /dev/null 2>&1 || :
pmsleep 0.5	# give server a chance to start
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '[P]PID|/[p]ython.*/haproxy/' >>$seq_full
echo "haproxy_stats_server pid: $spid" >>$seq_full
$sudo chcon system_u:object_r:haproxy_var_lib_t:s0 $(dirname $socket) $socket >/dev/null 2>&1 || :
pmda_install
echo

echo "=== report metric values ==="
metrics=`pminfo haproxy | LC_COLLATE=POSIX sort`
pminfo -dfmtT $metrics 2>&1 \
| $here/src/sortinst | pmda_filter | tee -a $seq_full

echo "=== verify metric values ==="
pminfo -v haproxy 2>&1 \
| $here/src/sortinst | pmda_filter | tee -a $seq_full

pmda_remove
status=0
exit