Skip to content

Commit

Permalink
Merge branch 'pcp2openmetrics' of https://github.com/lmchilton/pcp in…
Browse files Browse the repository at this point in the history
…to lmchilton-pcp2openmetrics
  • Loading branch information
natoscott committed Mar 20, 2024
2 parents 797226c + 7c9a49d commit e906ad3
Show file tree
Hide file tree
Showing 10 changed files with 1,509 additions and 14 deletions.
24 changes: 23 additions & 1 deletion qa/1131
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# PCP QA Test No. 1131
# Exercise pcp2json.
# Exercise pcp2json and pcp2openmetrics.
#
# Copyright (c) 2017 Red Hat.
#
Expand All @@ -16,13 +16,17 @@ $python -c "from collections import OrderedDict" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python collections OrderedDict module not installed"

which pcp2json >/dev/null 2>&1 || _notrun "pcp2json not installed"
which pcp2openmetrics >/dev/null 2>&1 || _notrun "pcp2openmetrics not installed"

status=1 # failure is the default!
signal=$PCP_BINADM_DIR/pmsignal
$sudo rm -rf $tmp $tmp.* $seq.full
trap "cd $here; rm -rf $tmp.*; exit \$status" 0 1 2 3 15

A="$here/archives/rep"
hostname=`hostname`
machineid=`_machine_id`
domainid=`_domain_name`

_archive_filter()
{
Expand All @@ -34,6 +38,19 @@ _value_filter()
sed 's/\(\.[0-9]\)[0-9]*/\1/g'
}

_filter_pcp2openmetrics()
{
tee -a $here/$seq.full \
| col -b \
| sed \
-e '/domainname=/ s/'$domainid'/DOMAINID/' \
-e '/machineid=/ s/'$machineid'/MACHINEID/' \
-e '/groupid=/ s/'$UID'/GROUPID/' \
-e '/userid=/ s/'$UID'/USERID/' \
-e '/hostname=/ s/'$hostname'/HOST/' \
| LC_COLLATE=POSIX sort
}

# real QA test starts here
echo "---"
pcp2json -a $A -H -I -z "" | _archive_filter
Expand All @@ -43,6 +60,11 @@ echo "---"
pcp2json -a $A -H -I -Z UTC+0 -x "" | _archive_filter
echo "---"
pcp2json -a $A -H -I -z -X -b GB -P 2 -F $tmp.outfile ""
echo "---"
pcp2openmetrics -s1 -H -z hinv.ncpu | _filter_pcp2openmetrics
echo "---"


cat $tmp.outfile | _archive_filter
which json_verify > /dev/null 2>&1
if [ $? -eq 0 ]; then
Expand Down
7 changes: 7 additions & 0 deletions qa/1131.out
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,13 @@ QA output created by 1131
}
}
---
---


# HELP hinv_ncpu number of CPUs in the system
# TYPE hinv_ncpu gauge
hinv_ncpu{domainname="DOMAINID",groupid="GROUPID",hostname="HOST",machineid="MACHINEID",userid="USERID",agent="linux"} 16
---
{
"@pcp": {
"@hosts": [
Expand Down
25 changes: 14 additions & 11 deletions qa/1589
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Exercise pcp2json HTTP POST functionality.
#
# Copyright (c) 2023 Red Hat. All Rights Reserved.
#
#

#set -x

seq=`basename $0`
echo "QA output created by $seq"
Expand Down Expand Up @@ -46,7 +48,9 @@ _filter_pcp2json_http()
| sed \
-e "s/\(\"@host\"\): \""$hostname"\"/\1:HOST/g" \
-e "s/\(\"value\"\): \""$cpus"\"/\1:NCPU/g" \
-e "s/\(\"@timestamp\"\): \"[1-9][0-9]*\"/\1:SECS/g" \
-e 's/\(\"@timestamp\"\): \(.*\)/\1:DATE TIME/' \
-e 's/- - \[[^]]*\]/- -[DATE]/g' \
-e 's/.*- -/[IP ADDRESS]/g' \
-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' \
Expand All @@ -60,21 +64,20 @@ _filter_pcp2json_http()

# real QA test starts here
port=`_find_free_port`
nc -l localhost $port >$tmp.nc.out 2>$tmp.nc.err &
pid1=$!
sleep 2 # let nc start up

# in case nc(1) does not exit by itself, e.g. on Ubuntu
( sleep 2; $signal $pid1 ) >>$seq.full 2>&1 &
$PCP_PYTHON_PROG $here/src/pythonserver.py $port &> $tmp.python.out &
pid=$!
sleep 2 # let server start up

echo "pcp2json invocation" | tee -a $here/$seq.full
pcp2json -s1 -f%s -ZUTC --url http://localhost:$port/receive hinv.ncpu > $tmp.json.out 2> $tmp.json.err
pcp2json -s1 -ZUTC -u http://localhost:$port hinv.ncpu >$tmp.json.out 2>$tmp.json.err

echo "pcp2json HTTP POST (sorted):"
_filter_pcp2json_http <$tmp.nc.out
_filter_pcp2json_http <$tmp.python.out

($signal $pid ) >>$seq.full 2>&1 &

echo "All diagnostics" >> $here/$seq.full
for i in $tmp.json.out $tmp.json.err $tmp.nc.out $tmp.nc.err
for i in $tmp.json.out $tmp.json.err $tmp.python.out
do
echo "=== $i ===" >>$here/$seq.full
cat $i >>$here/$seq.full
Expand Down
13 changes: 11 additions & 2 deletions qa/1589.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ QA output created by 1589
pcp2json invocation
pcp2json HTTP POST (sorted):





"value":NCPU
"ncpu": {
}
"@interval": "0",
"@timestamp":SECS,
"@timestamp":DATE TIME
"hinv": {
}
{
Expand All @@ -23,11 +27,16 @@ pcp2json HTTP POST (sorted):
"@pcp": {
}
Accept: */*
Body:
Content-Length: SIZE
Content-Type: application/json
Headers:
Host: localhost:PORT
POST /receive HTTP/1.1
INFO:root:POST request,
INFO:root:Starting httpd...
Path: /
User-Agent: python-requests VERSION
[IP ADDRESS][DATE] "POST / HTTP/1.1" 200 -
{
}

71 changes: 71 additions & 0 deletions qa/1827
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh
# PCP QA Test No. 1589
# 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"

_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`
$sudo rm -rf $tmp $tmp.* $seq.full
trap "_cleanup; exit \$status" 0 1 2 3 15


_filter_pcp2openmetrics_http()
{
tee -a $here/$seq.full \
| col -b \
| sed \
-e '/domainname=/ s/'$domainid'/DOMAINID/' \
-e '/machineid=/ s/'$machineid'/MACHINEID/' \
-e '/groupid=/ s/'$UID'/GROUPID/' \
-e '/userid=/ s/'$UID'/USERID/' \
-e '/hostname=/ s/'$hostname'/HOST/' \
-e 's/- - \[[^]]*\]/- -[DATE]/g' \
-e 's/.*- -/[IP ADDRESS]/g' \
-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 &
pid=$!
sleep 2 # let server start up

echo "pcp2openmetrics invocation" | tee -a $here/$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

($signal $pid ) >>$seq.full 2>&1 &

# success, all done
exit
23 changes: 23 additions & 0 deletions qa/1827.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
QA output created by 1827
pcp2openmetrics invocation
pcp2openmetrics HTTP POST (sorted):






# HELP hinv_ncpu number of CPUs in the system
# TYPE hinv_ncpu gauge
Accept: */*
Body:
Content-Length: SIZE
Content-Type: application/openmetrics-text
Headers:
Host: localhost:PORT
INFO:root:POST request,
INFO:root:Starting httpd...
Path: /
User-Agent: python-requests VERSION
[IP ADDRESS][DATE] "POST / HTTP/1.1" 200 -
hinv_ncpu{domainname="DOMAINID",groupid="GROUPID",hostname="HOST",machineid="MACHINEID",userid="USERID",agent="linux"} 16
46 changes: 46 additions & 0 deletions src/pcp2openmetrics/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright (c) 2024 Red Hat.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#

TOPDIR = ../..
include $(TOPDIR)/src/include/builddefs

TARGET = pcp2openmetrics
MAN_SECTION = 1
MAN_PAGES = $(TARGET).$(MAN_SECTION)
MAN_DEST = $(PCP_MAN_DIR)/man$(MAN_SECTION)
BASHDIR = $(PCP_BASHSHARE_DIR)/completions

default: $(TARGET).py $(MAN_PAGES)

default:

include $(BUILDRULES)

install: default
ifeq "$(HAVE_PYTHON)" "true"
$(INSTALL) -m 755 $(TARGET).py $(PCP_BIN_DIR)/$(TARGET)
$(INSTALL) -S $(BASHDIR)/pcp $(BASHDIR)/$(TARGET)
@$(INSTALL_MAN)
endif

default_pcp: default

install_pcp: install

check:: $(TARGET).py
$(PYLINT) $^

check :: $(MAN_PAGES)
$(MANLINT) $^

Loading

0 comments on commit e906ad3

Please sign in to comment.