-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports translation of pcp metrics into open telemetry format. Supports opentelemetry protocol http json format. Updated relevent qa tests, as well as created a new one (1977) to test the tools http functionality. Added man page and makefile.
- Loading branch information
Showing
7 changed files
with
1,630 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/sh | ||
# PCP QA Test No. 1827 | ||
# Exercise pcp2opentelemetry HTTP POST functionality. | ||
# | ||
# Copyright (c) 2024 Red Hat. All Rights Reserved. | ||
# | ||
|
||
|
||
seq=`basename $0` | ||
echo "QA output created by $seq" | ||
|
||
. ./common.python | ||
|
||
which pcp2opentelemetry >/dev/null 2>&1 || _notrun "pcp2opentelemetry 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_pcp2opentelemetry_http() | ||
{ | ||
tee -a $here/$seq.full \ | ||
| col -b \ | ||
| sed \ | ||
-e '/\"asDouble\":/ s/[0-9][0-9]*/NCPU/' \ | ||
-e 's/\"'$machineid'\"/MACHINEID/' \ | ||
-e 's/\"'$hostname'\"/HOSTNAME/' \ | ||
-e 's/\"'$domainid'\"/DOMAINID/' \ | ||
-e 's/\"agent\": .*/\"agent\": \"'$OSTYPE'\"/' \ | ||
-e 's/\"userid\": .*/\"userid\": USERID/' \ | ||
-e 's/\"userid\": .*/\"userid\": GROUPID/' \ | ||
-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' | ||
} | ||
|
||
|
||
# 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 "pcp2opentelemetry invocation" | tee -a $here/$seq.full | ||
pcp2opentelemetry -s1 -u http://localhost:$port/receive hinv.ncpu >$tmp.json.out 2>$tmp.openjson.err | ||
|
||
|
||
echo "pcp2opentelemetry HTTP POST (sorted):" | ||
_filter_pcp2opentelemetry_http <$tmp.python.out | ||
|
||
|
||
cp $tmp.python.out ~/chilton.txt | ||
|
||
|
||
($signal $pid ) >>$seq.full 2>&1 & | ||
|
||
|
||
# success, all done | ||
exit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
QA output created by 1977 | ||
pcp2opentelemetry invocation | ||
pcp2opentelemetry HTTP POST (sorted): | ||
INFO:root:Starting httpd... | ||
|
||
INFO:root:POST request, | ||
Path: /receive | ||
Headers: | ||
Host: localhost:PORT | ||
User-Agent: python-requests VERSION | ||
Accept: */* | ||
Content-Type: application/json | ||
Content-Length: SIZE | ||
|
||
|
||
|
||
Body: | ||
{ | ||
"resourceMetrics": [ | ||
{ | ||
"resource": { | ||
"attributes": [ | ||
{ | ||
"os.type": "linux", | ||
"service.name": "pcp", | ||
"telemetry.sdk.language": "python", | ||
"telemetry.sdk.name": "opentelemetry", | ||
"telemetry.sdk.version": "1.24.0" | ||
}, | ||
{ | ||
"server.address": "http://localhost:54337/receive" | ||
} | ||
] | ||
}, | ||
"scopeMetrics": [ | ||
{ | ||
"metrics": [ | ||
{ | ||
"description": "number of CPUs in the system", | ||
"gauge": { | ||
"dataPoints": [ | ||
{ | ||
"asDouble": NCPU, | ||
"attributes": [ | ||
{ | ||
"agent": "linux-gnu" | ||
"domainname": DOMAINID, | ||
"groupid": 4209557, | ||
"hostname": HOSTNAME, | ||
"machineid": MACHINEID, | ||
"semantics": "discrete", | ||
"type": "u32", | ||
"userid": GROUPID | ||
} | ||
], | ||
"startTimeUnixNano": 1714519586.062307 | ||
} | ||
] | ||
}, | ||
"name": "hinv.ncpu", | ||
"unit": "none" | ||
} | ||
], | ||
"scope": { | ||
"name": "pcp.hinv", | ||
"version": 1 | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
[IP ADDRESS][DATE] "POST /receive HTTP/1.1" 200 - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = pcp2opentelemetry | ||
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) $^ | ||
|
Oops, something went wrong.