Skip to content

Commit

Permalink
Add tool pcp2openmetrics for converting pcp metrics to open metric fo…
Browse files Browse the repository at this point in the history
…rmat

including two sets of revisions made from initial PR for pcp2openmetrics tool.
  • Loading branch information
lmchilton committed Feb 28, 2024
1 parent 1a78625 commit 6f41451
Show file tree
Hide file tree
Showing 10 changed files with 1,508 additions and 13 deletions.
25 changes: 24 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 @@ -9,20 +9,25 @@ seq=`basename $0`
echo "QA output created by $seq"

. ./common.python
. ./common.check

This comment has been minimized.

Copy link
@natoscott

natoscott Feb 28, 2024

Member

Don't need this new line as common.python includes common.check


$python -c "from pcp import pmapi" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python pcp pmapi module not installed"
$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 +39,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 +61,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
23 changes: 13 additions & 10 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 @@ -51,21 +53,22 @@ _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
pid2=$!
sleep 2

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

( sleep 2; $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": "2024-02-14 18:31:30",

This comment has been minimized.

Copy link
@natoscott

natoscott Feb 28, 2024

Member

This looks like we've lost some timestamp filtering here - is this expected? (is that timestamp fixed, e.g. from an archive?)

"hinv": {
}
{
Expand All @@ -22,11 +26,16 @@ pcp2json HTTP POST (sorted):
]
"@pcp": {
}
127.0.0.1 - - [14/Feb/2024 13:31:30] "POST / HTTP/1.1" 200 -

This comment has been minimized.

Copy link
@natoscott

natoscott Feb 28, 2024

Member

There's an unfiltered timestamp in the output here.

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
{
}
Expand Down
70 changes: 70 additions & 0 deletions qa/1827
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/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
. ./common.check

This comment has been minimized.

Copy link
@natoscott

natoscott Feb 28, 2024

Member

Don't need this second common.check line here.


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/^\(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
127.0.0.1 - - [28/Feb/2024 12:02:06] "POST / HTTP/1.1" 200 -

This comment has been minimized.

Copy link
@natoscott

natoscott Feb 28, 2024

Member

Unfiltered timestamp in the output here.

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
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 6f41451

Please sign in to comment.