File: 1827

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 (83 lines) | stat: -rwxr-xr-x 2,466 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
#!/bin/sh
# PCP QA Test No. 1827
# Exercise pcp2openmetrics HTTP POST functionality.
#
# Copyright (c) 2024 Red Hat.  All Rights Reserved.
# 

#set -x

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

. ./common.python

which pcp2openmetrics >/dev/null 2>&1 || _notrun "pcp2openmetrics not installed"
$python -c "from http.server import BaseHTTPRequestHandler, HTTPServer" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python import from http.server failed"

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
cpus=`pmprobe -v hinv.ncpu | awk '{print $3}'`
hostname=`hostname`
machineid=`_machine_id`
domainid=`_domain_name`
trap "_cleanup; exit \$status" 0 1 2 3 15

MYUID=`id -u`
MYGID=`id -g`

_filter_pcp2openmetrics_http()
{
    tee -a $seq_full \
    | col -b \
    | sed \
        -e '/domainname=/s/domainname="*'$domainid'"*/domainname="DOMAINID"/' \
        -e '/machineid=/s/machineid="*'$machineid'"*/machineid="MACHINEID"/' \
        -e '/groupid=/s/groupid="*'$MYGID'"*/groupid="GROUPID"/' \
        -e '/userid=/s/userid="*'$MYUID'"*/userid="USERID"/' \
        -e '/hostname=/ s/hostname="*'$hostname'"*/hostname="HOST"/' \
	-e 's/} [0-9][0-9]*$/} N (cpus)/' \
	-e '/HTTP/d' \
        -e "s/^\(Host: localhost\):$port/\1:PORT/g" \
        -e 's/^\(Content-Length:\) [1-9][0-9]*/\1 SIZE/g' \
        -e 's/^\(User-Agent: python-requests\).*/\1 VERSION/g' \
        -e 's/^\(Date:\).*/\1 DATE/g' \
        -e 's/\(\"context\":\) [0-9][0-9]*/\1 CTXID/g' \
        -e '/^Accept-Encoding: /d' \
        -e 's/\(\hostname=\): \""$hostname"\"/\1:HOST/g' \
        -e '/^Connection: keep-alive/d' \
        -e '/ using stream socket$/d' \
    | LC_COLLATE=POSIX sort
}

# real QA test starts here
port=`_find_free_port`
$PCP_PYTHON_PROG $here/src/pythonserver.py $port >$tmp.python.out 2>&1 &
pid=$!
sleep 2 # let server start up

echo "---" 
echo "pcp2openmetrics invocation" | tee -a $seq_full
pcp2openmetrics -s1 -u http://localhost:$port hinv.ncpu >$tmp.openmetrics.out 2>$tmp.openmetrics.err

echo "pcp2openmetrics HTTP POST (sorted):"
_filter_pcp2openmetrics_http <$tmp.python.out

cat /dev/null > $tmp.python.out

echo "---"
echo "testing -x option" | tee -a $seq_full
pcp2openmetrics -s1 -x -u http://localhost:$port hinv.ncpu >$tmp.openmetrics2.out 2>$tmp.openmetrics2.err
_filter_pcp2openmetrics_http <$tmp.python.out

# terminate pythonserver.py now
pmsignal $pid >/dev/null 2>&1 

# success, all done
exit