openMetrics PMDA (OpenMetrics PMDA)
SCRIPTED SOURCES
Executable scripts present in the
$PCP_PMDAS_DIR/openmetrics/config.d directory or sub-directories
will be executed and the stdout
stream containing openmetrics
formatted metric data will be parsed as though it had come from a
URL or file. The stderr
stream from a script will be sent to the
PMDA log file, which by default can be found in
$(PCP_LOG_DIR)/pmcd/openmetrics.log
.
Note that scripted sources do not support label or metric
filtering (as described above for URL sources) - they can simply
do their own filtering in the script itself with sed(1), awk
(1),
or whatever tool is desired.
A simple example of a scripted config entry follows:
#! /bin/sh
awk '{
print("# HELP loadavg local load average")
print("# TYPE loadavg gauge")
printf("loadavg {interval=\"1-minute\"} %.2f\n", $1)
printf("loadavg {interval=\"5-minute\"} %.2f\n", $2)
printf("loadavg {interval=\"15-minute\"} %.2f\n", $3)
}' /proc/loadavg
This script produces the following OpenMetrics-formatted metric
data when run:
# HELP loadavg local load average
# TYPE loadavg gauge
loadavg {interval="1-minute"} 0.12
loadavg {interval="5-minute"} 0.27
loadavg {interval="15-minute"} 0.54
If the above script was saved and made executable in a file named
$PCP_PMDAS_DIR/openmetrics/config.d/local/system.sh then this
would result in a new PCP metric named
openmetrics.local.system.loadavg
which would have three instances
for the current load average values: 1-minute
, 5-minute
and
15-minute
.
Scripted config entries may produce more than one PCP leaf metric
name. For example, the above "system.sh" script could also
export other metrics such as CPU statistics, by reading
/proc/stat on the local system. Such additional metrics would
appear as peer metrics in the same PCP metric subtree. In the
case of CPU counters, the metric type definition should be
counter
, not gauge
. For full details of the openmetrics
exposition formats, see
https://github.com/OpenObservability/OpenMetrics/blob/master/specification/OpenMetrics.md .