PMWEBAPI(3) | Library Functions Manual | PMWEBAPI(3) |
PMWEBAPI - introduction to the Performance Metrics Web Application Programming Interface
The PMWEBAPI interface is a binding of a subset of the PMAPI to the web. It uses HTTP as transport, REST as organizational style for request/parameter encoding (the GET and POST methods are interchangeable), and JSON as response encoding. A context identifier is used as a persistent way to refer to PMAPI contexts across related web requests. These context identifiers expire after a configurable period of disuse.
Errors generally result in HTTP-level error responses. An Access-Control-Allow-Origin: * header is added to all JSON responses.
To create a new web context identifier, a web client invokes:
In addition, the web client may add the parameter &polltimeout=MMMM for a maximum interval (in seconds) between expected accesses to the given context. This value is limited by pmwebd configuration, and is a courtesy to allow pmwebd to free up memory earlier in case of sudden web application shutdown.
If successful, the response from these requests is a JSON document of the form:
{ "context" : NNNNN }
The number (a 32-bit unsigned decimal) is then used in all later operations.
In addition, permanent contexts may be created by pmwebd at initialization using its -h, -a, -L command line options, so that a set of fixed NNNNN numbers may be made available to web clients.
The general form of the requests is as follows: /pmapi/NNNNN/OPERATION where
The general form of the requests is as follows:
The response is a JSON document that provides the metric metadata as an array. For example:
{ "metrics": [
{ "name":"foo.bar", "pmID":PPPP, "indom":DDDD,
"type":"32", "sem":"instant", "units":"MHz",
"text-oneline":"foo bar", "text-help":"blah blah blah" },
{ "name":"foo.bar2", ... }
...
] }
Most of the fields are self-explanatory.
PM_SEM_COUNTER "counter" |
PM_SEM_INSTANT "instant" |
PM_SEM_DISCRETE "discrete" |
The general form of the requests is as follows:
If any of the names/pmids are valid, the response is a JSON document that provides the values for all requested metrics, for all their instances.
{ "timestamp": { "s":SEC, "us":USEC },
"values": [
{ "pmid":PPPP1, "name":"NAME1",
"instances:" [
{ "instance":IIII1, "value":VALUE1 }
{ "instance":IIII2, "value":VALUE2 }
...
] },
{ "pmid":PPPP2, "name":"NAME2", ... }
...
] }
Most of the fields are self-explanatory. Numeric metric types are represented as JSON integer or floating-point values. Strings are passed verbatim, except that non-ASCII values are replaced with a Unicode 0xFFFD REPLACEMENT CHARACTER code. Event type metrics are not currently supported.
The general form of the requests is as follows:
In addition, either query may be suffixed with:
The response is a JSON document that provides the metric metadata as an array. For example:
{ "indom":DDDD,
"instances": [
{ "instance":IIII, "name":"INAME" }
...
] }
The general form of these requests is as follows:
The general form of these requests is as follows:
In addition, either query may be suffixed with:
If successful, the response from these requests is a JSON document of the form:
{ "success" : true }
Prometheus exporting of live metrics from a preexisting PMWEBAPI context is available:
The general form of the requests is:
For all numeric metrics with the given NAME prefixes, create a prometheus text export format giving their current value and related metadata. The response has text/plain type rather than JSON, and is designed to be ingested by a Prometheus server, or pcp's own pmdaprometheus.
The native PCP metric metadata (metric name, semantics and units) are first output with the # PCP prefix. If the units string is empty, then none is output. The units metadata string may contain spaces and extends to the end of the line. Prometheus metric types are heuristically inferred from PCP metric types, and units/scales are converted to base seconds/bytes/count if possible, with a corresponding suffix added to the metric name. PCP metric names are mapped so that . are exchanged with :. Instance domain instances are represented as Prometheus labels with quoted instance names.
# PCP proc.nprocs instant none # HELP proc:nprocs instantaneous number of processes # TYPE proc:nprocs gauge proc:nprocs 7 # PCP kernel.pernode.cpu.intr counter millisec # HELP kernel:pernode:cpu:intr_seconds_total total interrupt CPU time from /proc/stat for each node # TYPE kernel:pernode:cpu:intr_seconds_total counter kernel:pernode:cpu:intr_seconds_total{instance="node0"} 25603.540000000001 # PCP filesys.blocksize instant byte # HELP filesys:blocksize_bytes Size of each block on mounted filesystem (Bytes) # TYPE filesys:blocksize_bytes gauge filesys:blocksize_bytes{instance="/dev/mapper/docker-253:0-83713-\ 9a130460b46163fcf4443710db3159dea6bb5ec2aaca108515839a7a28c191ce"} 4096 filesys:blocksize_bytes{instance="/dev/mapper/VolGroup00-root17"} 4096
When enabled, pmwebd can emulate a subset of the graphite web-api to allow web applications like graphite and grafana to extract data from all archives under the configured -A directory. The graphite namespace is constructed from the PCP archives using a simple mapping that encodes the Cartesian product of archives, metrics, and instance-domain instances into dot-separated strings. Some metacharacter-quoting is employed to encode general strings into components. Only numeric PCP metrics are exposed; COUNTER semantic values are rate-converted.
position | number | purpose |
1 | 1 | encoded pathname of the archive .meta file (default), |
or canonicalized archive hostname (-J mode) | ||
2 | N | the N components of the pcp metric name |
N+2 | 1 | instance name of the metric (if any) |
Since glob wildcarding is supported within metric name components, using them in the first component (an encoding of the archive name) is a good way to identify machines, or to match multiple archives spanning times of interest.
We list here only the broadest outline of the supported calls. pmwebd does not support every graphite web-api option, so many querystring parameters may be ignored. Arithmetic/statistical functions on metrics are not supported.
PCPIntro(1), PCPIntro(3), pmwebd(1), http://graphite.readthedocs.org/ and PMAPI(3)
PCP | Performance Co-Pilot |