forked from performancecopilot/pcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pcp-geolocate: setup standard labels for geolocation (optional)
Provides a utility and systemd service to automate translation of IP address based latitude and longitude lookup, for storing as metric labels. Handy for building map-based tools.
- Loading branch information
Showing
11 changed files
with
328 additions
and
16 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,37 @@ | ||
#!/bin/sh | ||
# PCP QA Test No. 1803 | ||
# Exercise pcp-geolocate(1) metric labels. | ||
# | ||
# Copyright (c) 2023 Red Hat. All Rights Reserved. | ||
# | ||
|
||
seq=`basename $0` | ||
echo "QA output created by $seq" | ||
|
||
. ./common.python | ||
|
||
$sudo rm -rf $tmp $tmp.* $seq.full | ||
|
||
_cleanup() | ||
{ | ||
cd $here | ||
$sudo rm -rf $tmp $tmp.* | ||
} | ||
|
||
status=0 # success is the default! | ||
trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
|
||
_filter() | ||
{ | ||
sed \ | ||
-e 's/"latitude": .*,$/LATITUDE/g' \ | ||
-e 's/"longitude": .*$/LONGITUDE/g' \ | ||
# end | ||
} | ||
|
||
# real QA test starts here | ||
$PCP_BINADM_DIR/pcp-geolocate $tmp.geo | ||
pmjson < $tmp.geo | _filter | ||
|
||
# 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,5 @@ | ||
QA output created by 1803 | ||
{ | ||
LATITUDE, | ||
LONGITUDE | ||
} |
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,2 @@ | ||
pcp-geolocate.1.gz | ||
pcp-geolocate.service |
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,52 @@ | ||
# | ||
# Copyright (c) 2022-2023 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 = pcp-geolocate | ||
SCRIPT = $(TARGET).py | ||
MAN_SECTION = 1 | ||
MAN_PAGES = $(TARGET).$(MAN_SECTION) | ||
MAN_DEST = $(PCP_MAN_DIR)/man$(MAN_SECTION) | ||
LDIRT = $(TARGET).service | ||
|
||
default: $(SCRIPT) $(MAN_PAGES) $(TARGET).service | ||
|
||
include $(BUILDRULES) | ||
|
||
install: default | ||
ifeq "$(HAVE_PYTHON)" "true" | ||
$(INSTALL) -m 755 $(SCRIPT) $(PCP_BINADM_DIR)/$(TARGET) | ||
ifeq ($(ENABLE_SYSTEMD),true) | ||
$(INSTALL) -m 644 $(TARGET).service $(PCP_SYSTEMDUNIT_DIR)/$(TARGET).service | ||
endif | ||
@$(INSTALL_MAN) | ||
endif | ||
|
||
default_pcp : default | ||
|
||
install_pcp : install | ||
|
||
$(TARGET).service: $(TARGET).service.in | ||
$(SED) <$< >$@ \ | ||
-e 's;@PCP_BINADM_DIR@;'$(PCP_BINADM_DIR)';' \ | ||
-e 's;@PCP_SYSCONF_DIR@;'$(PCP_SYSCONF_DIR)';' \ | ||
# END | ||
|
||
check :: $(SCRIPT) | ||
$(PYLINT) $^ | ||
|
||
check :: $(MAN_PAGES) | ||
$(MANLINT) $^ |
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,68 @@ | ||
'\"macro stdmacro | ||
.\" | ||
.\" Copyright (c) 2022-2023 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. | ||
.\" | ||
.\" | ||
.TH PCP-GEOLOCATE 1 "PCP" "Performance Co-Pilot" | ||
.SH NAME | ||
\f3pcp-geolocate\f1 \- discover collector system geographical labels | ||
.SH SYNOPSIS | ||
\f3pcp\f1 \f3geolocate\f1 | ||
.SH DESCRIPTION | ||
.B pcp-geolocate | ||
reports the latitude and longitude for the local Performance Co-Pilot | ||
collector host in JSON format. | ||
This geolocation information is sourced from the cache file | ||
.I $PCP_SYSCONF_DIR/labels/optional/geolocate | ||
if it exists, else an attempt is made to perform geolocation based | ||
on the host IP address, via several online sources (REST APIs). | ||
.PP | ||
The output from this command is suited for storing as metric labels by | ||
saving it to the cache file mentioned above. | ||
.PP | ||
The opt-in | ||
.BR systemd (1) | ||
service unit file for this command provides an automated location | ||
discovery for PCP metric labels. | ||
.SH METRIC LABELS | ||
The JSON output is the preferred format for storing geographical location | ||
as PCP metric labels. | ||
Every PCP metric available from this host will be tagged with the labels | ||
for latitude and longitude, enabling tools that make use of this such as | ||
the Grafana geomap panel. | ||
.PP | ||
For more information about metric labels refer to the | ||
.BR pmcd (1), | ||
.BR pminfo (1), | ||
.BR pmlogger (1) | ||
and | ||
.BR pmLookupLabels (3) | ||
manual entries. | ||
.SH PCP ENVIRONMENT | ||
Environment variables with the prefix \fBPCP_\fP are used to parameterize | ||
the file and directory names used by PCP. | ||
On each installation, the | ||
file \fI/etc/pcp.conf\fP contains the local values for these variables. | ||
The \fB$PCP_CONF\fP variable may be used to specify an alternative | ||
configuration file, as described in \fBpcp.conf\fP(5). | ||
.SH SEE ALSO | ||
.BR PCPIntro (1), | ||
.BR pmcd (1), | ||
.BR pminfo (1), | ||
.BR pmseries (1), | ||
.BR pmlogger (1), | ||
.BR systemd (1), | ||
.BR pmLookupLabels (3), | ||
.BR pcp.conf (5) | ||
and | ||
.BR pcp.env (5). |
Oops, something went wrong.