'\"macro stdmacro .\" .\" Copyright (c) 2017-2018 Red Hat. .\" Copyright (c) 2017 Ronak Jain. .\" .\" 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. .\" .ds ia prometheus .ds Ia Prometheus .TH PMDAPROMETHEUS 1 "PCP" "Performance Co-Pilot" .SH NAME \f3pmdaprometheus\f1 \- Prometheus PMDA .SH SYNOPSIS \f3$PCP_PMDAS_DIR/prometheus/pmdaprometheus\f1 [\f3\-D\f1] [\f3\-n\f1] [\f3\-c\f1 \f2config\f1] [\f3\-d\f1 \f2domain\f1] [\f3\-l\f1 \f2logfile\f1] [\f3\-r\f1 \f2root\f1] [\f3\-t\f1 \f2timeout\f1] [\f3\-u\f1 \f2user\f1] .SH DESCRIPTION \fBpmdaprometheus\fR is a Performance Metrics Domain Agent (PMDA) which creates PCP metrics from Prometheus endpoints, which provide HTTP based access to application metrics. The default \f2config\fP directory is .BR $PCP_PMDAS_DIR/prometheus/config.d/ , see ``CONFIGURATION SOURCES'' below. The default URL fetch \f2timeout\fP is \fB2\fP seconds. The default \f2user\fP, if not specified with the \f3\-u\fP option, is the current user. If the .B \-n option is given, the list of configuration files will not be sorted prior to processing. This list is sorted by default but that can be expensive if there are a large number of configuration files (URLs and/or scripts). .PP If the .B \-D option is given, additional diagnostic messages will be written to the PMDA log file, which is .B $PCP_LOG_DIR/pmcd/prometheus.log by default (see also .BR \-l below). In addition, the metric .B prometheus.control.debug controls the same debug flag and can be set with the following command: .br .in +0.5i .BI "pmstore prometheus.control.debug" " value" .in .br where .I value is either .B 1 (to enable verbose log messages) or .BR 0 (to disable verbose log messages). This is particularly useful for examining the http headers passed to each fetch request, filter settings and other processing details that are logged when the debugging flag is enabled. .PP The .B \-d option may be used to override the default performance metrics .I domain number, which defaults to .BR 144. It is strongly recommended not to change this. The .I domain number should be different for every PMDA on the one host, and the same .I domain number should be used for .B pmdaprometheus PMDA on all hosts. See also the .B \-r option, which allows the root of the dynamic namespace to be changed from the default .BR prometheus . .PP The .B \-l option may be used to specify .I logfile as the destination for PMDA messages instead of the default, .BR $PCP_LOG_DIR/pmcd/prometheus.log . As a special case, .I logfile may be \fB"\-"\fP to send messages to the .B stderr stream instead, e.g. .BR \-l- . This would normally be the .B stderr stream for the parent process, .BR pmcd (1), which may itself have redirected .BR stderr . This redirection is normally most useful in a containerized environment, or when using .BR dbpmda (1). .PP The .B \-r option allows the root of the dynamic namespace to be changed to .I root from the default, .BR prometheus . In conjunction with other command line options, this allows .B pmdaprometheus to be deployed as a different PMDA with distinct metrics namespace and metrics domain on the same host system. Note that all PMDAs require a unique domain number so the .B \-d option must also be specified. Use of the .B \-r option may also change the defaults for some other command line options, e.g. the default log file name and the default configuration directory. .SH "CONFIGURATION SOURCES" As it runs, .B pmdaprometheus periodically recursively scans the .B $PCP_PMDAS_DIR/prometheus/config.d directory (or the directory specified with the .B \-c option), looking for source URL files (\c .IR *.url ) and executable scripts or binaries. Any files that do not have the .B .url suffix or are not executable, are ignored \- this allows documentation files such as "README" and non-executable "common" script function definitions to be present without being considered as config files. .PP A remote server does not have to be up or stay running \- the PMDA tolerates remote URLs that may come and go over time. The PMDA will relay data and metadata when/if they are available, and will return errors when/if they are down. PCP metric IDs, internal and external instance domain identifiers are persisted and will be restored when individual metric sources become available and/or when the PMDA is restarted. In addition, the PMDA checks directory modification times and will rescan for new or changed configuration files dynamically. It is .I not necessary to restart the PMDA when adding, removing or changing configuration files. .SH "URL SOURCES" Each file with the .I .url suffix found in the config directory or sub-directory contains one complete HTTP or HTTPS URL at which .B pmdaprometheus can reach a Prometheus endpoint. Local file access is also supported with a conventional .I file://somepath/somefile URL, in which case .I somepath/somefile should contain prometheus formatted metric data. .PP The first line of a .I .url config file should be the URL, as described above. Subsequent lines, if any, are prefixed with a keyword that can be used to alter the http GET request. A keyword must end with .B ':' (colon) and the text extends to the end of the line. Comment lines that start with .B # and blank lines are ignored. The only currently supported keywords are .B HEADER: and .BR FILTER: . .PP .B HEADER: .I "headername\fB:\fP value ... to end of line" .br Adds .I headername and its value to the headers passed in the http GET request for the configured URL. An example configuration file that provides 3 commonly used headers and an authentication token might be : .PP .in 1i .ft CW .nf http://somehost/path/endpoint.html # this is a comment HEADER: Accept: text/html HEADER: Keep-Alive: 300 HEADER: Connection: keep-alive HEADER: Authorization: token ABCDEF1234567890 .in .fi .ft 1 .PP As mentioned above, header values extend to the end of the line. They may contain any valid characters, including colons. Multiple spaces will be collapsed to a single space, and leading and trailing spaces are trimmed. A common use for headers is to configure a proxy agent and the assorted parameters it may require. .PP .BI "FILTER: INCLUDE METRIC" " regex" .br or .br .BI "FILTER: EXCLUDE METRIC" " regex" .br Dynamically created metric names that match .I regex will be either included or excluded in the name space, as specified. The simple rule is that the \fIfirst matching\fP filter regex for a particular metric name is the rule that prevails. If no filter regex matches (or there are no filters), then the metric is included by default, i.e. the default filter if none are specified is .BR "FILTER: INCLUDE METRIC .*" This is backward compatible with older versions of the configuration file that did not support filters. Multiple .B FILTER: lines would normally be used, e.g. to include some metrics but exclude all others, use .B "FILTER: EXCLUDE METRIC .*" as the last of several filters that include the desired metrics. Conversely, to exclude some metrics but include all others, use .B "FILTER: EXCLUDE METRIC" .IR regex . In this case it's not necessary (though doesn't hurt) to specify the final .B "FILTER: INCLUDE METRIC .*" because, as stated above, any metric that does not match any filter regex will be included by default. .PP Label filtering uses similar .B FILTER: syntax and semantics. .BI "FILTER: EXCLUDE LABEL" " regex" will delete all labels matching .I regex from all metrics defined in the configuration file. The same rules as for metrics apply for labels too - an implicit rule: .BI "FILTER: INCLUDE LABEL .*" applies to all labels that do not match any earlier filter rule. .P Caution is needed with label filtering because by default, all labels are used to construct the PCP instance name. By excluding some labels, the instance names will change. Excluding all labels for a particular metric changes that metric to be singular, i.e. have no instance domain. In addition, by excluding some labels, different instances of the same metric may become duplicates. When such duplicates occur, the last duplicate instance returned by the end-point URL prevails over any earlier instances. For these reasons, it is recommended that label filtering rules be configured when the configuration file is first defined, and not changed thereafter. If a label filtering change is required, the configuration file should be renamed, which effectively defines a new metric, with the new (or changed) instance naming. .P Unrecognized keywords in configuration files are reported in the PMDA log file but otherwise ignored. .SH "SCRIPTED SOURCES" Executable scripts present in the .I $PCP_PMDAS_DIR/prometheus/config.d directory or sub-directories will be executed and the .B stdout stream containing prometheus formatted metric data will be parsed as though it had come from a URL or file. The .B stderr stream from a script will be sent to the PMDA log file, which by default can be found in .BR $(PCP_LOG_DIR)/pmcd/prometheus.log . .PP 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 .BR sed (1), .BR awk (1), or whatever tool is desired. .PP A simple example of a scripted config entry follows: .in 1i .ft CW .nf #! /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 .in .fi .ft 1 This script produces the following Prometheus-formatted metric data when run: .in 1i .ft CW .nf # 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 .in .fi .ft 1 If the above script was saved and made executable in a file named .I $PCP_PMDAS_DIR/prometheus/config.d/local/system.sh then this would result in a new PCP metric named .B prometheus.local.system.loadavg which would have three instances for the current load average values: .BR 1-minute , .B 5-minute and .BR 15-minute . .PP 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 .I /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 .BR counter , not .BR gauge . For full details of the prometheus exposition formats, see .IR https://prometheus.io/docs/instrumenting/exposition_formats . .SH "METRIC NAMING" All metrics from a file named .IR JOB .* will be exported as PCP metrics with the .I prometheus.JOB metric name prefix. Therefore, the JOB name must be a valid non-leaf name for PCP PMNS metric names. If the .I JOB name has multiple dot-separated components, the resulting PMNS names will include those components and care is needed to ensure there are no overlapping definitions, e.g. metrics returned by .B JOB.response may overlap or conflict with metrics returned by .BR JOB.response.time . .PP Config file entries (URLs or scripts) found in subdirectories of the config directory will also result in hierarchical metric names. For example, a config file named .B $PCP_PMDAS_DIR/prometheus/config.d/mysource/latency/get.url will result in metrics being created (by fetching that source URL) below .BR prometheus.mysource.latency.get in the PCP namespace. Scripts found in subdirectories of the config directory similarly result in hierarchical PCP metric names. .SH "DYNAMIC METRIC NAMES" As described above, changes and new additions can be made to files in the configuration directory without having to restart the PMDA. These changes are detected automatically and the PCP metric names below .B prometheus in the PMNS will be updated accordingly, i.e. new metrics will be dynamically added and/or existing metrics removed. In addition, .B pmdaprometheus honors the PMCD_NAMES_CHANGE .BR pmFetch (3) protocol that was introduced in PCP version 4.0. In particular, if .B prometheus metrics are being logged by a PCP version 4.0 or later .BR pmlogger (1), new metrics that appear as a result of changes in the PMDA configuration directory will automatically start to be logged, provided the root of the .B prometheus PMDA namespace is configured for logging in the .B pmlogger configuration file. See .BR pmlogger (1) for details. An example of such a .B pmlogger configuration file is : .in 1i .ft CW .nf log mandatory on 2 second { # log all metrics below the root of the prometheus namespace prometheus } .in .fi .ft 1 .SH "CONTROL METRICS" The PMDA maintains special control metrics, as described below. Apart from .BR prometheus.control.debug , each of these metrics is a counter and has one instance for each configured metric source. The instance domain is adjusted dynamically as new sources are discovered. If there are no sources configured, the metric names are still defined but the instance domain will be empty and a fetch will return no values. .IP \fBprometheus.control.calls\fP total number of times each configured metric source has been fetched (if it's a URL) or executed (if it's a script), since the PMDA started. .IP \fBprometheus.control.fetch_time\fP Total time in milliseconds that each configured metric source has taken to return a document, excluding the time to parse the document. .IP \fBprometheus.control.parse_time\fP Total time in milliseconds that each configured metric source has taken to parse each document, excluding the time to fetch the document. .PP When converted to a rate, the \fBcalls\fP metric represents the average fetch rate of each source over the sampling interval (time delta between samples). The \fBfetch_time\fP and \fBparse_time\fP counters, when converted to a rate, represent the average fetch and parsing latency (respectfully), during the sampling interval. .PP The .BR prometheus.control.debug metric has a singular value, defaulting to .BR 0 . If a non-zero value is stored into this metric using .BR pmstore (1), additional debug messages will be written to the PMDA log file. .SH LIMITATIONS .B pmdaprometheus and .B libpcp internals impose some numerical constraints about the number of sources (4095), metrics (1024) within each source, and instances for each metric (4194304). .SH INSTALLATION Install the Prometheus PMDA by using the Install script as root: .PP # cd $PCP_PMDAS_DIR/prometheus .br # ./Install .PP To uninstall, do the following as root: .PP # cd $PCP_PMDAS_DIR/prometheus .br # ./Remove .PP .B pmdaprometheus is launched by .BR pmcd (1) and should never be executed directly. The Install and Remove scripts notify .B pmcd when the agent is installed or removed. .PP When scripts and .I .url files are added, removed or changed in the configuration directory, it is usually not necessary to restart the PMDA \- the changes will be detected and managed on subsequent requests to the PMDA. .SH FILES .IP "\fB$PCP_PMDAS_DIR/prometheus/Install\fR" 4 installation script for the \fBpmdaprometheus\fR agent .IP "\fB$PCP_PMDAS_DIR/prometheus/Remove\fR" 4 undo installation script for the \fBpmdaprometheus\fR agent .IP "\fB$PCP_PMDAS_DIR/prometheus/config.d/\fR" 4 contains URLs and scripts used by the \fBpmdaprometheus\fR agent as sources of prometheus metric data. .IP "\fB$PCP_LOG_DIR/pmcd/prometheus.log\fR" 4 default log file for error messages from \fBpmdaprometheus\fR .IP "\fB$PCP_VAR_DIR/config/144.*\fR" 4 files containing internal tables for metric and instance ID number persistence (domain 144). .SH PCP ENVIRONMENT Environment variables with the prefix \fBPCP_\fR are used to parameterize the file and directory names used by \fBPCP\fR. On each installation, the file .I /etc/pcp.conf contains the local values for these variables. The \fB$PCP_CONF\fR variable may be used to specify an alternative configuration file, as described in .IR pcp.conf (5). .SH SEE ALSO .BR pmcd (1), .BR pminfo (1), .BR pmlogger (1), .BR pmstore (1), .BR PMWEBAPI (3), .BR pmFetch (3) and .IR https://prometheus.io/docs/instrumenting/exposition_formats .