1PMWEBAPI(3) Library Functions Manual PMWEBAPI(3)
2
3
4
6 PMWEBAPI - introduction to the Performance Metrics Web Application Pro‐
7 gramming Interface
8
10 GET /metrics
11 GET /series/...
12 GET /search/...
13 GET /pmapi/...
14
16 #include <pcp/pmwebapi.h>
17
18 ... assorted routines ...
19
20 cc ... -lpcp_web -lpcp
21
23 The PMWEBAPI is a collection of interfaces providing Performance Co-Pi‐
24 lot services for web applications. It consists of APIs for web appli‐
25 cations querying and analysing both live and historical performance
26 data, as well as APIs used by web servers.
27
28 The usual HTTP URL-encoded optional parameter rules apply and PMWEBAPI
29 REST requests always follow the convention:
30
31 /api/endpoint?parameter1=value1¶meter2=value2
32
33 Examples in all following sections use the curl(1) command line utility
34 with a local pmproxy(1) server listening on port 44322 (default port).
35 The pmjson(1) utility is used to neatly format any JSON output, as op‐
36 posed to the compact (minimal whitespace) form provided by default.
37 The examples in the scalable time series section use historical data
38 recorded by the pmlogger(1) service, in conjunction with a local redis-
39 server(1).
40
42 Exporting of live performance metrics in an Open Metrics compatible
43 format (as described at https://openmetrics.io and popularized by the
44 https://prometheus.io project) is available.
45
46 All requests are performed on the web server host by default, unless a
47 hostspec parameter is provided.
48
49 GET /metrics
50 ┌───────────┬─────────┬────────────────────────────────────────────────┐
51 │Parameters │ Type │ Explanation │
52 ├───────────┼─────────┼────────────────────────────────────────────────┤
53 │names │ string │ Comma-separated list of metric names │
54 │times │ boolean │ Append sample times (milliseconds since epoch) │
55 ├───────────┼─────────┼────────────────────────────────────────────────┤
56 │hostspec │ string │ Host specification as described in PCPIntro(1) │
57 └───────────┴─────────┴────────────────────────────────────────────────┘
58 Fetches current values and metadata for all metrics, or only metrics
59 indicated by a comma-separated list of names.
60
61 For all numeric metrics with the given NAME prefixes, create an Open
62 Metrics (Prometheus) text export format giving their current value and
63 related metadata.
64
65 The response has plain text type rather than JSON commonly used else‐
66 where in the REST API. This format can be injested by many open source
67 monitoring tools, including Prometheus and pmdaopenmetrics(1).
68
69 The native PCP metric metadata (metric name, type, indom, semantics and
70 units) is first output for each metric with # PCP prefix. The metadata
71 reported is of the form described on pmTypeStr(3), pmInDomStr(3), pm‐
72 SemStr(3) and pmUnitsStr(3) respectively. If the pmUnitsStr(3) units
73 string is empty, then none is output. The units metadata string may
74 contain spaces and extends to the end of the line.
75
76 PCP metric names are mapped so that the . separators are exchanged with
77 _ (':' in back-compatibility mode, where "# PCP" is the identifying
78 line suffix). Both metric labels and instances are represented as
79 Prometheus labels, with external instance names being quoted and the
80 flattened PCP metric hierarchy being presented with each value.
81
82 $ curl -s http://localhost:44322/metrics?names=proc.nprocs,kernel.pernode.cpu.intr,filesys.blocksize
83
84 # PCP5 proc.nprocs 3.8.99 u32 PM_INDOM_NULL instant none
85 # HELP proc_nprocs instantaneous number of processes
86 # TYPE proc_nprocs gauge
87 proc_nprocs {hostname="app1"} 7
88
89 # PCP5 kernel.pernode.cpu.intr 60.0.66 u64 60.19 counter millisec
90 # HELP kernel_pernode_cpu_intr total interrupt CPU [...]
91 # TYPE kernel_pernode_cpu_intr counter
92 kernel_pernode_cpu_intr{hostname="app1",instname="node0"} 25603
93
94 # PCP5 filesys.blocksize 60.5.9 u32 60.5 instant byte
95 # HELP filesys_blocksize Size of each block on mounted file[...]
96 # TYPE filesys_blocksize gauge
97 filesys_blocksize{hostname="app1",instname="/dev/sda1"} 4096
98 filesys_blocksize{hostname="app1",instname="/dev/sda2"} 4096
99
101 The fast, scalable time series query capabilities provided by the pm‐
102 series(1) command are also available through a REST API. These queries
103 provide access to performance data (metric metadata and values) from
104 multiple hosts simultaneously, and in a fashion suited to efficient re‐
105 trieval by any number of web applications.
106
107 All requests in this group can be accompanied by an optional client pa‐
108 rameter. The value passed in the request will be sent back in the re‐
109 sponse - all responses will be in JSON object form in this case, with
110 top level "client" and "result" fields.
111
112 GET /series/query - pmSeriesQuery(3)
113 ┌───────────┬────────┬────────────────────────────────────────────┐
114 │Parameters │ Type │ Explanation │
115 ├───────────┼────────┼────────────────────────────────────────────┤
116 │expr │ string │ Query string in pmseries(1) format │
117 │client │ string │ Request identifier sent back with response │
118 └───────────┴────────┴────────────────────────────────────────────┘
119 Performs a time series query for either matching identifiers, or match‐
120 ing identifiers with series of time-stamped values.
121
122 The query is in the format described in pmseries(1) and is passed to
123 the server via either the expr parameter (HTTP GET) or via the message
124 body (HTTP POST).
125
126 When querying for time series matches only, no time window options are
127 specified and matching series identifiers are returned in a JSON array.
128
129 $ curl -s 'http://localhost:44322/series/query?expr=disk.dev.read*' | pmjson
130 [
131 "9d8c7fb51ce160eb82e3669aac74ba675dfa8900",
132 "ddff1bfe286a3b18cebcbadc1678a68a964fbe9d",
133 "605fc77742cd0317597291329561ac4e50c0dd12"
134 ]
135
136 When querying for time series values as well, a time window must be
137 specified as part of the query string. The simplest form is to just
138 request the most recent sample.
139
140 $ curl -s 'http://localhost:44322/series/query?expr=disk.dev.read*[samples:1]' | pmjson
141 [
142 {
143 "series": "9d8c7fb51ce160eb82e3669aac74ba675dfa8900",
144 "instance": "c3795d8b757506a2901c6b08b489ba56cae7f0d4",
145 "timestamp": 1547483646.2147431,
146 "value": "12499"
147 }, {
148 "series": "ddff1bfe286a3b18cebcbadc1678a68a964fbe9d",
149 "instance": "6b08b489ba56cae7f0d4c3795d8b757506a2901c",
150 "timestamp": 1547485701.7431218,
151 "value": "1118623"
152 }, {
153 "series": "605fc77742cd0317597291329561ac4e50c0dd12",
154 "instance": "c3795d8b757506a2901c6b08b489ba56cae7f0d4",
155 "timestamp": 1547483646.2147431,
156 "value": "71661"
157 }
158 ]
159
160 GET /series/values - pmSeriesValues(3)
161 ┌───────────┬────────┬────────────────────────────────────────────┐
162 │Parameters │ Type │ Explanation │
163 ├───────────┼────────┼────────────────────────────────────────────┤
164 │series │ string │ Comma-separated list of series identifiers │
165 │client │ string │ Request identifier sent back with response │
166 ├───────────┼────────┼────────────────────────────────────────────┤
167 │samples │ number │ Count of samples to return │
168 │interval │ string │ Time between successive samples │
169 │start │ string │ Sample window start time │
170 │finish │ string │ Sample window end time │
171 │offset │ string │ Sample window offset │
172 │align │ string │ Sample time alignment │
173 │zone │ string │ Time window timezone │
174 └───────────┴────────┴────────────────────────────────────────────┘
175 Performs values retrievals for one or more time series identifiers.
176 The JSON response contains the same information as the pmseries
177 -q/--query option using any of the time window parameters described on
178 pmseries(1). If no time window parameters are specified, the single
179 most recent value observed is retrieved.
180
181 $ curl -s http://localhost:44322/series/values?series=605fc77742cd0317597291329561ac4e50c0dd12 | pmjson
182 [
183 {
184 "series": "605fc77742cd0317597291329561ac4e50c0dd12",
185 "timestamp": 1317633022959.959241041,
186 "value": "71660"
187 }
188 ]
189
190 GET /series/descs - pmSeriesDescs(3)
191 ┌───────────┬────────┬────────────────────────────────────────────┐
192 │Parameters │ Type │ Explanation │
193 ├───────────┼────────┼────────────────────────────────────────────┤
194 │series │ string │ Comma-separated list of series identifiers │
195 │client │ string │ Request identifier sent back with response │
196 └───────────┴────────┴────────────────────────────────────────────┘
197 Performs a descriptor lookup for one or more time series identifiers.
198 The JSON response contains the same information as the pmseries
199 -d/--desc option.
200
201 $ curl -s http://localhost:44322/series/descs?series=605fc77742cd0317597291329561ac4e50c0dd12 | pmjson
202 [
203 {
204 "series": "605fc77742cd0317597291329561ac4e50c0dd12",
205 "source": "f5ca7481da8c038325d15612bb1c6473ce1ef16f",
206 "pmid": "60.0.4",
207 "indom": "60.1",
208 "semantics": "counter",
209 "type": "u32",
210 "units": "count",
211 }
212 ]
213
214 GET /series/labels - pmSeriesLabels(3), pmSeriesLabelValues(3)
215 ┌───────────┬────────┬────────────────────────────────────────────┐
216 │Parameters │ Type │ Explanation │
217 ├───────────┼────────┼────────────────────────────────────────────┤
218 │series │ string │ Comma-separated list of series identifiers │
219 │match │ string │ Glob pattern string to match on all labels │
220 │name │ string │ Find all known label values for given name │
221 │names │ string │ Comma-separated list of label names │
222 │client │ string │ Request identifier sent back with response │
223 └───────────┴────────┴────────────────────────────────────────────┘
224 This command operates in one of three modes. It can perform a label
225 set lookup for one or more time series identifiers, when given the
226 series parameter). It can produce a list of all known label names, in
227 the absence of name, names or series parameters. The JSON responses
228 for these modes contains the same information as the pmseries
229 -l/--labels option.
230
231 Alternatively, it can produce a list of all known label values for a
232 given label name or names. The JSON response for this mode contains
233 the same information as the pmseries -v/--values option.
234
235 $ curl -s http://localhost:44322/series/labels?series=605fc77742cd0317597291329561ac4e50c0dd12 | pmjson
236 [
237 {
238 "series": "605fc77742cd0317597291329561ac4e50c0dd12",
239 "labels": {
240 "agent": "linux",
241 "domainname": "acme.com",
242 "groupid": 1000,
243 "hostname": "www.acme.com",
244 "latitude": -25.28496,
245 "longitude": 152.87886,
246 "machineid": "295b16e3b6074cc8bdbda8bf96f6930a",
247 "platform": "dev",
248 "userid": 1000
249 }
250 }
251 ]
252
253 Alternatively, with no name, names or series parameters, return the
254 list of all known label names.
255
256 $ curl -s http://localhost:44322/series/labels | pmjson
257 [
258 "agent",
259 "appversion",
260 "domainname",
261 "groupid",
262 "hostname",
263 "jobid",
264 "latitude",
265 "longitude",
266 "machineid",
267 "platform",
268 "userid"
269 ]
270
271 Use the name or names parameters to find all possible label values for
272 the given name(s).
273
274 $ curl -s http://localhost:44322/series/labels?names=hostname,domainname | pmjson
275 {
276 "hostname": [ "app", "nas" ],
277 "domainname": [ "acme.com" ]
278 }
279
280 GET /series/metrics - pmSeriesMetrics(3)
281 ┌───────────┬────────┬────────────────────────────────────────────┐
282 │Parameters │ Type │ Explanation │
283 ├───────────┼────────┼────────────────────────────────────────────┤
284 │series │ string │ Comma-separated list of series identifiers │
285 │match │ string │ Glob pattern string to match on all names │
286 │client │ string │ Request identifier sent back with response │
287 └───────────┴────────┴────────────────────────────────────────────┘
288 Performs a metric name lookup for one or more time series identifiers.
289 The JSON response contains the same information as the pmseries
290 -m/--metrics option.
291
292 $ curl -s http://localhost:44322/series/metrics?series=605fc77742cd0317597291329561ac4e50c0dd12 | pmjson
293 [
294 {
295 "series": "605fc77742cd0317597291329561ac4e50c0dd12",
296 "name": "disk.dev.read_bytes"
297 }
298 ]
299
300 Alternatively, with no series argument, this request will return the
301 list of all known metric names.
302
303 $ curl -s http://localhost:44322/series/metrics | pmjson
304 [
305 "disk.dev.read",
306 "disk.dev.read_bytes",
307 "disk.dev.read_merge",
308 "kernel.all.load",
309 "kernel.all.pswitch",
310 ...
311 ]
312
313 GET /series/sources - pmSeriesSources(3)
314 ┌───────────┬────────┬─────────────────────────────────────────────┐
315 │Parameters │ Type │ Explanation │
316 ├───────────┼────────┼─────────────────────────────────────────────┤
317 │series │ string │ Comma-separated list of source identifiers │
318 │match │ string │ Glob pattern string to match on all sources │
319 │client │ string │ Request identifier sent back with response │
320 └───────────┴────────┴─────────────────────────────────────────────┘
321 Performs a lookup for one or more time series sources, returning an ar‐
322 ray of all PMAPI context names used to access the time series from that
323 source. The JSON response contains the same information as the pm‐
324 series -S/--source option.
325
326 $ curl -s http://localhost:44322/series/sources?source=2cd6a38f9339f2dd1f0b4775bda89a9e7244def6 | pmjson
327 [
328 {
329 "source": "2cd6a38f9339f2dd1f0b4775bda89a9e7244def6",
330 "context": [
331 "/var/log/pcp/pmlogger/acme",
332 "www.acme.com"
333 ]
334 }
335 ]
336
337 GET /series/instances - pmSeriesInstances(3)
338 ┌───────────┬────────┬───────────────────────────────────────────────┐
339 │Parameters │ Type │ Explanation │
340 ├───────────┼────────┼───────────────────────────────────────────────┤
341 │series │ string │ Comma-separated list of series identifiers │
342 │match │ string │ Glob pattern string to match on all instances │
343 │client │ string │ Request identifier sent back with response │
344 └───────────┴────────┴───────────────────────────────────────────────┘
345 Provide instance identifiers and names for one or more time series
346 identifiers. The JSON response contains the same information as the
347 pmseries -i/--instance option.
348
349 $ curl -s http://localhost:44322/series/instances?series=605fc77742cd0317597291329561ac4e50c0dd12 | pmjson
350 [
351 {
352 "series": "605fc77742cd0317597291329561ac4e50c0dd12",
353 "source": "97261ac7742cd4e50c0d03175913295d12605fc7",
354 "instance": "c3795d8b757506a2901c6b08b489ba56cae7f0d4"
355 "id": 1,
356 "name": "sda",
357 }, {
358 "series": "605fc77742cd0317597291329561ac4e50c0dd12",
359 "source": "97261ac7742cd4e50c0d03175913295d12605fc7",
360 "instance": "57506a2901c6b08b489ba56cae7f0d4c3795d8b7"
361 "id": 2,
362 "name": "sdb",
363 }
364 ]
365
366 Alternatively, with no series argument, this request will return the
367 list of all known instance names.
368
369 $ curl -s http://localhost:44322/series/instances | pmjson
370 [
371 "1 minute",
372 "5 minute",
373 "15 minute",
374 "cpu0",
375 "cpu1",
376 "cpu2",
377 "cpu3",
378 "node0",
379 "node1",
380 "sda",
381 "sdb",
382 ...
383 ]
384
385 GET /series/load - pmSeriesLoad(3)
386 ┌───────────┬────────┬────────────────────────────────────────────┐
387 │Parameters │ Type │ Explanation │
388 ├───────────┼────────┼────────────────────────────────────────────┤
389 │expr │ string │ Source load string in pmseries(1) format │
390 │client │ string │ Request identifier sent back with response │
391 └───────────┴────────┴────────────────────────────────────────────┘
392 Load time series performance data from the specified source into the
393 redis-server cache. This request is equivalent to the pmseries
394 -l/--load option.
395
396 $ curl -s http://localhost:44322/series/load?expr={source.name:"/var/log/pcp/pmlogger/acme"}
397 {
398 "success": true
399 }
400
402 The full text search capabilities provided by the pmsearch(1) command
403 are also available through a REST API. These queries provide access to
404 an index over performance metric names, instances, instance domains and
405 help text, suitable for a metric search engine, and in a fashion suited
406 to efficient querying by any number of web applications.
407
408 In order to use this functionality, the optional RediSearch module must
409 be loaded in the redis-server at the time pmproxy is started, such that
410 metrics, instances and help text it discovers can be automatically in‐
411 dexed.
412
413
414 GET /search/text - pmSearchTextQuery(3)
415 ┌───────────┬────────┬─────────────────────────────────────────────┐
416 │Parameters │ Type │ Explanation │
417 ├───────────┼────────┼─────────────────────────────────────────────┤
418 │query │ string │ Query string in pmsearch(1) format │
419 │highlight │ fields │ Include matching markup in response fields │
420 │offset │ number │ Result offset cursor for pagination │
421 │limit │ number │ Maximum results to include in response │
422 │field │ fields │ Queried fields (defaults to all) │
423 │return │ fields │ Fields to actually return (defaults to all) │
424 │type │ types │ Entity types to filter (defaults to all) │
425 └───────────┴────────┴─────────────────────────────────────────────┘
426 Performs a text search query across metrics and instance domains - all
427 forms of names and help texts.
428
429 The mandatory search string is further described in pmsearch(1) and is
430 passed to the server via the query parameter (HTTP GET).
431
432 $ curl -s http://localhost:44322/search/text?query=halt | pmjson
433 {
434 "total": 2,
435 "offset": 0,
436 "limit": 10,
437 "elapsed": 0.000504,
438 "results": [
439 {
440 "name": "kvm.halt_exits",
441 "type": "metric",
442 "indom": "95.0.4",
443 "oneline": "Number of guest exits due to halt calls.",
444 "helptext": "This type of exit is usually seen when a guest is idle."
445 },
446 {
447 "name": "kvm.halt_wakeup",
448 "type": "metric",
449 "indom": "95.0.6",
450 "oneline": "Number of wakeups from a halt.",
451 }
452 ]
453 }
454
455 The available search entity types are metric, indom and instance.
456 Query parameters highlight and field take name, oneline and helptext.
457
458 Query parameter return takes name, type, oneline, helptext, indom.
459 There is typically both a name and help text associated with metrics.
460 Contents of these are then matched against query. An instance domain
461 has help text and a numeric identifier, while instances have a name on‐
462 ly (which can be searched).
463
464 GET /search/suggest - pmSearchTextSuggest(3)
465 ┌───────────┬────────┬────────────────────────────────────┐
466 │Parameters │ Type │ Explanation │
467 ├───────────┼────────┼────────────────────────────────────┤
468 │query │ string │ Search query for search engine │
469 │limit │ number │ Max results to include in response │
470 └───────────┴────────┴────────────────────────────────────┘
471 Provides search query suggestions, that is, metric and instance names.
472
473 The mandatory search string is further described in pmsearch(1) and is
474 passed to the server via the query parameter (HTTP GET).
475
476 $ curl -s http://localhost:44322/search/suggest?query=disk&limit=4 | pmjson
477 [
478 "disk.all.avactive",
479 "disk.all.aveq",
480 "disk.all.blkread",
481 "disk.all.blktotal"
482 ]
483
484 GET /search/indom - pmSearchTextInDom(3)
485 ┌───────────┬────────┬─────────────────────────────────────┐
486 │Parameters │ Type │ Explanation │
487 ├───────────┼────────┼─────────────────────────────────────┤
488 │query │ string │ Target indom for search engine │
489 │offset │ number │ Result offset cursor for pagination │
490 │limit │ number │ M results to include in response │
491 └───────────┴────────┴─────────────────────────────────────┘
492 Provides all entities (instances, metrics) related to indom, including
493 itself, that is passed to the server via the query parameter.
494
495 GET /search/info - pmSearchInfo(3)
496 Provides metrics relating to operation of the search engine, in partic‐
497 ular showing document and text record counts.
498
499 $ curl -s http://localhost:44322/search/info | pmjson
500 {
501 "docs": 1589,
502 "terms": 3855,
503 "records": 116831,
504 "records_per_doc_avg": 73.52,
505 "bytes_per_record_avg": 6.36,
506 "inverted_sz_mb": 0.71,
507 "inverted_cap_mb": 0.00,
508 "inverted_cap_ovh": 0.00,
509 "skip_index_size_mb": 0.00,
510 "score_index_size_mb": 0.00,
511 "offsets_per_term_avg": 9.41,
512 "offset_bits_per_record_avg": 8.00
513 }
514
516 The live performance collection facilities available from pmcd(1) can
517 also be accessed through a REST API.
518
519 All requests are performed on the web server host by default, unless
520 either a hostspec or context parameter is provided. hostname can be
521 used in place of hostspec.
522
523 Context identifiers are used as a persistent way to refer to PMAPI con‐
524 texts across related web requests. These contexts expire after a con‐
525 figurable period of disuse, and are either explicitly allocated using
526 the /pmapi/context interface, or implicitly allocated using other in‐
527 terfaces.
528
529 The timeout interval is configurable at context creation time, and as
530 such the polltime parameter can be used anywhere the hostspec is speci‐
531 fied. It sets the context timeout in terms of length of inactive time.
532 The unit for the timeout value is seconds and the default is 5.
533
534 To specify a specific existing context in any PMAPI web request, the
535 endpoints can be accessed with either the context parameter or embedded
536 in the endpoint URL itself, such as /pmapi/[number]/fetch.
537
538 GET /pmapi/context - pmNewContext(3)
539 ┌────────────┬────────┬────────────────────────────────────────────────┐
540 │Parameters │ Type │ Explanation │
541 ├────────────┼────────┼────────────────────────────────────────────────┤
542 │hostspec │ string │ Host specification as described in PCPIntro(1) │
543 │polltimeout │ number │ Seconds of inactivity before closing context │
544 │client │ string │ Request identifier sent back with response │
545 └────────────┴────────┴────────────────────────────────────────────────┘
546 To create a context for live sampling, a web client can access any
547 /pmapi URL (optionally using the hostspec or context parameter). If no
548 context exists, a new one will be created for that web client, and its
549 identifier returned for future accesses.
550
551 However, /pmapi/context is provided as a dedicated URL for applications
552 wishing to explicitly create the contexts they use.
553
554 If successful, the server responds with a HTTP 200 (OK) code and JSON
555 message body of the form:
556
557 $ curl -s http://localhost:44322/pmapi/context?hostspec=www.acme.com&polltime=500 | pmjson
558 {
559 "context": 348734,
560 "source": "05af7f3eb840277fd3cfa91f90ef0067199743c",
561 "hostspec": "www.acme.com",
562 "labels": {
563 "domainname": "acme.com",
564 "groupid": 1000,
565 "hostname": "www.acme.com",
566 "machineid": "295b7623b6074cc8bdbda8bf96f6930a"
567 "platform": "dev",
568 "userid": 1000
569 }
570 }
571
572 The context (a 32-bit unsigned decimal number) can then be used with
573 all later requests.
574
575 In the case of a hostspec containing authentication information, such
576 as a username, the server will follow the HTTP Basic Authentication
577 protocol to ascertain necessary authentication details from the user,
578 providing the client web application an opportunity to request these
579 from the user.
580
581 GET /pmapi/metric - pmLookupDesc(3), pmLookupLabels(3), pmLookupName(3),
582 pmLookupText(3)
583 ┌────────────┬────────┬────────────────────────────────────────────────┐
584 │Parameters │ Type │ Explanation │
585 ├────────────┼────────┼────────────────────────────────────────────────┤
586 │name │ string │ An individual metric name │
587 │names │ string │ Comma-separated list of metric names │
588 │pmid │ pmID │ Numeric or pmIDStr(3) metric identifier │
589 │pmids │ string │ Comma-separated numeric or pmIDStr(3) pmIDs │
590 │prefix │ string │ Metric namespace component as in PMNS(5) │
591 ├────────────┼────────┼────────────────────────────────────────────────┤
592 │hostspec │ string │ Host specification as described in PCPIntro(1) │
593 │context │ number │ Web context number (optional like hostspec) │
594 │polltimeout │ number │ Seconds of inactivity before context closed │
595 │client │ string │ Request identifier sent back with response │
596 └────────────┴────────┴────────────────────────────────────────────────┘
597 The metric endpoint provides detailed PMAPI metric metadata for one or
598 more metrics. If no parameters are supplied, the response will be for
599 all metrics found when traversing the entire Performance Metrics Name
600 Space (PMNS).
601
602 The prefix parameter can be used to specify a subtree of the PMNS for
603 traversal. Alternatively, a specific metric or comma-separated list of
604 metrics can be specified using either name or names
605
606 The server response is a JSON document that provides metric metadata as
607 an array.
608
609 $ curl -s http://localhost:44322/pmapi/metric?names=kernel.all.load,disk.all.read | pmjson
610 {
611 "context": 348734,
612 "metrics": [
613 {
614 "name": "kernel.all.load",
615 "pmid": "60.2.0",
616 "indom": "60.2",
617 "type": "FLOAT",
618 "sem": "instant",
619 "units": "none",
620 "series": "d2b28c7f6dc0d69ffd21dba7ba955e78c37719b",
621 "source": "05af7f3eb840277fd3cfa91f90ef0067199743c",
622 "labels": {
623 "agent": "linux",
624 "domainname": "acme.com",
625 "groupid": 1000,
626 "hostname": "www.acme.com",
627 "platform": "dev",
628 "userid": 1000
629 },
630 "text-oneline": "1, 5 and 15 minute load average"
631 },
632 {
633 "name": "disk.all.read",
634 "pmid": "60.0.24",
635 "type": "U64",
636 "sem": "counter",
637 "units": "count",
638 "series": "d2b28c7f6dc0d69ffd21dba7ba955e78c37719b",
639 "source": "05af7f3eb840277fd3cfa91f90ef0067199743c",
640 "labels": {
641 "agent": "linux",
642 "domainname": "acme.com",
643 "groupid": 1000,
644 "hostname": "www.acme.com",
645 "platform": "dev",
646 "userid": 1000
647 },
648 "text-oneline": "total read operations, summed for all disks",
649 "text-help": "Cumulative number of disk read operations [...]"
650 }
651 ]
652 }
653 Most of the fields are directly transcribed from the PMAPI calls for
654 metric descriptors, labels and help text mentioned above and are exact‐
655 ly as would be observed using the pminfo(1) command with the -dlmstT
656 options.
657
658 The semantics, type and units fields are as returned by pmTypeStr(3),
659 pmUnitsStr(3) and pmSemStr(3).
660
661 GET /pmapi/fetch - pmFetch(3)
662 ┌────────────┬────────┬────────────────────────────────────────────────┐
663 │Parameters │ Type │ Explanation │
664 ├────────────┼────────┼────────────────────────────────────────────────┤
665 │delta │ string │ Sampling interval in pmParseInterval(3) form │
666 │name │ string │ An individual metric name │
667 │names │ string │ Comma-separated list of metric names │
668 │pmid │ pmID │ Numeric or pmIDStr(3) metric identifier │
669 │pmids │ string │ Comma-separated numeric or pmIDStr(3) pmIDs │
670 ├────────────┼────────┼────────────────────────────────────────────────┤
671 │hostspec │ string │ Host specification as described in PCPIntro(1) │
672 │context │ number │ Web context number (optional like hostspec) │
673 │polltimeout │ number │ Seconds of inactivity before context closed │
674 │client │ string │ Request identifier sent back with response │
675 └────────────┴────────┴────────────────────────────────────────────────┘
676 This request fetches (samples) current values for given metrics.
677
678 If any of the names or pmids provided are valid, the response is a JSON
679 document that provides the values for all instances of the metrics, un‐
680 less a instance profile has been set for the web context (see section
681 on InDom profiles below).
682
683 $ curl -s http://localhost:44322/pmapi/fetch?names=kernel.all.load,disk.all.read | pmjson
684 {
685 "context": 348734,
686 "timestamp": 1547483646.2147431,
687 "values": [
688 {
689 "pmid": "60.2.0",
690 "name": "kernel.all.load",
691 "instances:" [
692 { "instance": 1, "value": 0.1 },
693 { "instance": 5, "value": 0.17 },
694 { "instance": 15, "value": 0.22 }
695 ]
696 },
697 {
698 "pmid":"60.0.24",
699 "name":"disk.all.read",
700 "instances:" [
701 { "instance": null, "value": 639231 }
702 ]
703 }
704 ]
705 }
706 The response fields map directly to fields from the underlying pm‐
707 Fetch(3) sampling interface.
708
709 Numeric metric types are represented as JSON integer or floating-point
710 values. Strings are passed verbatim, except that non-ASCII values are
711 replaced with a Unicode 0xFFFD replacement character code.
712
713 In backward compatibility mode the timestamp is presented as a JSON map
714 with second (sec) and microsecond (us) fields, instead of using the
715 more compact floating point representation shown above.
716
717 GET /pmapi/children - pmGetChildren(3), pmGetChildrenStatus(3)
718 ┌────────────┬────────┬────────────────────────────────────────────────┐
719 │Parameters │ Type │ Explanation │
720 ├────────────┼────────┼────────────────────────────────────────────────┤
721 │prefix │ string │ Metric namespace component as in PMNS(5) │
722 ├────────────┼────────┼────────────────────────────────────────────────┤
723 │hostspec │ string │ Host specification as described in PCPIntro(1) │
724 │context │ number │ Web context number (optional like hostspec) │
725 │polltimeout │ number │ Seconds of inactivity before context closed │
726 │client │ string │ Request identifier sent back with response │
727 └────────────┴────────┴────────────────────────────────────────────────┘
728 The children endpoint provides iterative namespace traversal for a con‐
729 text. If no parameters are supplied, the response will describe the
730 direct descendants of the Performance Metrics Name Space (PMNS) root.
731
732 The prefix parameter can be used to specify a subtree of the PMNS for
733 traversal.
734
735 The server response is a JSON document that provides the set of leaf
736 and non-leaf nodes below the given namespace node or root.
737
738 $ curl -s http://localhost:44322/pmapi/children?prefix=mem | pmjson
739 {
740 "context": 348734,
741 "name": "mem",
742 "leaf": [
743 "physmem",
744 "freemem"
745 ],
746 "nonleaf": [
747 "util",
748 "numa",
749 "vmstat",
750 "buddyinfo",
751 "slabinfo",
752 "zoneinfo",
753 "ksm"
754 ]
755 }
756
757 GET /pmapi/indom - pmGetInDom(3), pmNameInDom(3), pmLookupInDom(3)
758 ┌────────────┬─────────┬────────────────────────────────────────────────┐
759 │Parameters │ Type │ Explanation │
760 ├────────────┼─────────┼────────────────────────────────────────────────┤
761 │iname │ string │ Comma-separated list of instance names │
762 │indom │ pmInDom │ Numeric or pmInDomStr(3) instance domain │
763 │instance │ number │ Comma-separated list of instance numbers │
764 │match │ string │ Pattern matching style (exact, glob or regex) │
765 │name │ string │ An individual metric name │
766 ├────────────┼─────────┼────────────────────────────────────────────────┤
767 │hostspec │ string │ Host specification as described in PCPIntro(1) │
768 │context │ number │ Web context number (optional like hostspec) │
769 │polltimeout │ number │ Seconds of inactivity before context closed │
770 │client │ string │ Request identifier sent back with response │
771 └────────────┴─────────┴────────────────────────────────────────────────┘
772 This request lists the current instances of an instance domain. The
773 instance domain is either specified directly (in numeric or string
774 form) or indirectly, by association with the specified metric.
775
776 The request can be further qualified with a comma-separated list of the
777 instances to report on, either by name or number, using the instance
778 and iname parameters.
779
780 In the case of instance name qualifiers, these will be matched by exact
781 string comparison by default. Alternatively, the match parameter can
782 be used to specify that regular expression or glob pattern matching
783 should be used instead.
784
785 The response is a JSON document that provides the instance domain meta‐
786 data as an array.
787
788 $ curl -s http://localhost:44322/pmapi/indom?name=kernel.all.load | pmjson
789 {
790 "context": 348734,
791 "indom": "60.2",
792 "labels": {
793 "domainname": "acme.com",
794 "groupid": 1000,
795 "hostname": "www.acme.com",
796 "machineid": "295b7623b6074cc8bdbda8bf96f6930a"
797 "platform": "dev",
798 "userid": 1000
799 },
800 "instances": [
801 {
802 "instance": 1,
803 "name": "1 minute"
804 "labels": { ... },
805 },
806 {
807 "instance": 5,
808 "name": "5 minute"
809 "labels": { ... },
810 },
811 {
812 "instance": 15,
813 "name": "15 minute"
814 "labels": { ... },
815 }
816 ]
817 }
818
819 GET /pmapi/profile - pmAddProfile(3), pmDelProfile(3)
820 ┌────────────┬─────────┬────────────────────────────────────────────────┐
821 │Parameters │ Type │ Explanation │
822 ├────────────┼─────────┼────────────────────────────────────────────────┤
823 │iname │ string │ Comma-separated list of instance names │
824 │indom │ pmInDom │ Numeric or pmInDomStr(3) instance domain │
825 │instance │ number │ Comma-separated list of instance numbers │
826 │expr │ string │ One of "add" or "del" (mandatory). │
827 │match │ string │ Pattern matching style (exact, glob or regex) │
828 ├────────────┼─────────┼────────────────────────────────────────────────┤
829 │hostspec │ string │ Host specification as described in PCPIntro(1) │
830 │context │ number │ Web context number (optional like hostspec) │
831 │polltimeout │ number │ Seconds of inactivity before context closed │
832 │client │ string │ Request identifier sent back with response │
833 └────────────┴─────────┴────────────────────────────────────────────────┘
834 Some PMAPI operations can be performed with an active instance domain
835 profile which restricts (filters) the set of resulting instances re‐
836 turned, as described on pmAddProfile(3).
837
838 $ curl -s http://localhost:44322/pmapi/profile?expr=add,indom=60.2,iname=1%20minute
839 { "context": 348734, "success": true }
840
841 GET /pmapi/store - pmStore(3)
842 ┌────────────┬────────┬────────────────────────────────────────────────┐
843 │Parameters │ Type │ Explanation │
844 ├────────────┼────────┼────────────────────────────────────────────────┤
845 │iname │ string │ Comma-separated list of instance names │
846 │instance │ number │ Comma-separated list of instance numbers │
847 │name │ string │ An individual metric name │
848 │value │ (any) │ New value for the given metric instance(s) │
849 ├────────────┼────────┼────────────────────────────────────────────────┤
850 │hostspec │ string │ Host specification as described in PCPIntro(1) │
851 │context │ number │ Web context number (optional like hostspec) │
852 │polltimeout │ number │ Seconds of inactivity before context closed │
853 │client │ string │ Request identifier sent back with response │
854 └────────────┴────────┴────────────────────────────────────────────────┘
855 Some performance metrics allow their value to be modified, for example
856 to re-initialize counters or to modify control variables.
857
858 This operation takes a single metric name to modify, and optionally
859 specific instances. The mandatory value will be interpreted according
860 to the type of the metric being modified.
861
862 If successful, the response from these requests is a JSON document of
863 the form:
864
865 $ curl -s http://localhost:44322/pmapi/store?name=pmcd.control.timeout&value=10
866 {
867 "context": 348734,
868 "success": true
869 }
870
871 GET /pmapi/derive: pmAddDerived(3)
872 ┌────────────┬────────┬────────────────────────────────────────────────┐
873 │Parameters │ Type │ Explanation │
874 ├────────────┼────────┼────────────────────────────────────────────────┤
875 │expr │ string │ Derived metric expression │
876 │name │ string │ New derived metric name │
877 ├────────────┼────────┼────────────────────────────────────────────────┤
878 │hostspec │ string │ Host specification as described in PCPIntro(1) │
879 │context │ number │ Web context number (optional like hostspec) │
880 │polltimeout │ number │ Seconds of inactivity before context closed │
881 │client │ string │ Request identifier sent back with response │
882 └────────────┴────────┴────────────────────────────────────────────────┘
883 Create a new derived metric, as defined by the pmAddDerived(3) metric
884 interface. Derived metrics are associated with the named context, or a
885 new context is created and returned in the result.
886
887 This interface is one of the few that allows a POST to be used in place
888 of a GET. In this case the HTTP POST request body may be used to pro‐
889 vide one or more derived metrics specifications (all at once, across
890 multiple lines, as a convenience).
891
892 $ curl -s http://localhost:44322/pmapi/derive?name=blkio.avgsz&expr=disk.all.blktotal/disk.all.total | pmjson
893 {
894 "context": 348734,
895 "success": true
896 }
897
898 $ curl -s http://localhost:44322/pmapi/fetch?name=blkio.avgsz&samples=2 | pmjson
899 {
900 "context": 348734,
901 "timestamp": 1547483648.2147428,
902 "values": [
903 {
904 "pmid": "511.0.27",
905 "name": "blkio.avgsz",
906 "instances:" [
907 {
908 "instance": null,
909 "value": 9231
910 }
911 ]
912 }
913 ]
914 }
915
916 GET /pmapi/metrics: pmLookupDesc(3),pmLookupLabels(3), pmFetch(3)
917 ┌────────────┬─────────┬────────────────────────────────────────────────┐
918 │Parameters │ Type │ Explanation │
919 ├────────────┼─────────┼────────────────────────────────────────────────┤
920 │names │ string │ Comma-separated list of metric names │
921 │times │ boolean │ Append sample times (milliseconds since epoch) │
922 ├────────────┼─────────┼────────────────────────────────────────────────┤
923 │context │ number │ Web context number (optional like hostspec) │
924 │hostspec │ string │ Host specification as described in PCPIntro(1) │
925 │polltimeout │ number │ Seconds of inactivity before context closed │
926 │client │ string │ Request identifier sent back with response │
927 └────────────┴─────────┴────────────────────────────────────────────────┘
928 This request is a subset of the style described in the ``OPEN METRICS''
929 section, allowing a web context identifier to be passed as a parameter.
930 It is otherwise very similar in terms of parameters and response han‐
931 dling, please refer to the earlier section for details.
932
934 For the REST APIs, errors generally result in HTTP-level error respons‐
935 es. Wherever possible, any PMAPI error string will also be provided in
936 a message along with the response.
937
938 All responses will be returned using HTTP 1.1 protocol and with chunked
939 encoding being used to stream responses that are larger than a config‐
940 ured maximum size. Compression will be used on responses whenever the
941 client indicates appropriate support.
942
943 An Access-Control-Allow-Origin: * header is added to all REST API re‐
944 sponses.
945
947 PCPIntro(1), curl(1), pmcd(1), pmdaopenmetrics(1), pminfo(1), pmj‐
948 son(1), pmlogger(1), pmproxy(1), pmseries(1), redis-server(1), PCPIn‐
949 tro(3) and PMAPI(3)
950
951
952
953Performance Co-Pilot PCP PMWEBAPI(3)