| 1 |
= cockpit.js: Metrics |
| 2 |
|
| 3 |
Metrics about the system can be retrieved from several sources using |
| 4 |
link:#cockpit-metrics-function[`+cockpit.metrics()+`] metrics channels. The |
| 5 |
metrics are made available as series data, and can be used with the |
| 6 |
xref:cockpit-series-data.adoc#cockpit-series[`+cockpit.series()+`] and |
| 7 |
xref:cockpit-series-data.adoc#cockpit-grid[`+cockpit.grid()+`] facilities. |
| 8 |
|
| 9 |
[[cockpit-metrics-function]] |
| 10 |
== cockpit.metrics() |
| 11 |
|
| 12 |
.... |
| 13 |
metrics = cockpit.metrics(interval, options, cache) |
| 14 |
.... |
| 15 |
|
| 16 |
Opens a new metrics channel. The data retrieved will be available in the |
| 17 |
link:#cockpit-metrics-series[`+metrics.series+`] series sink, and can be |
| 18 |
used together with xref:cockpit-series-data.adoc#cockpit-grid[`+cockpit.grid()+`] objects. |
| 19 |
|
| 20 |
The `+interval+` is in milliseconds, and is the granularity of the |
| 21 |
series data retrieved. Any grids consuming the data must have the same |
| 22 |
interval. |
| 23 |
|
| 24 |
The `+cache+` argument is a cache identifier. If specified, then this |
| 25 |
metrics channel will share data with other metrics channels of the same |
| 26 |
identifier. Make sure to use a globally unique string. |
| 27 |
|
| 28 |
The `+options+` argument is either a javascript plain object, or an |
| 29 |
array of those. Each object can have the following fields. |
| 30 |
|
| 31 |
`+"metrics"+`:: |
| 32 |
An array of full metric descriptions, as javascript objects. The |
| 33 |
specifics of these, and how to determine which ones to use, can |
| 34 |
unfortunately only be found in the low-level protocol documentation. |
| 35 |
This option is required. |
| 36 |
`+"source"+`:: |
| 37 |
The source to use for real-time data. This is used by the `+follow+` |
| 38 |
method, see below. Set to `+"internal"+` to retrieve internal metrics |
| 39 |
read by the bridge. If set to `+"direct"+` or `+"pmcd"+` then data |
| 40 |
will be retrieved from https://pcp.io[PCP]if it is available. The |
| 41 |
default is `+"internal"+`. |
| 42 |
`+"archive_source"+`:: |
| 43 |
The source to use for retrieving historical data. This is used by the |
| 44 |
`+fetch+` method, see below. Set to `+"pcp-archive"+` to retrieve data |
| 45 |
from PCP archives. The default is not to try to retrieve historical |
| 46 |
data. |
| 47 |
|
| 48 |
When the `+options+` argument is an array of javascript objects, then |
| 49 |
the metrics channel tries to use them in order until one succeeds. This |
| 50 |
way, you can prefer PCP as the source but fall back to internal metrics |
| 51 |
when PCP is not available, for example. The channel gives no indication |
| 52 |
which of the options has been used, and `+fetch+` and `+follow+` might |
| 53 |
use different entries from the list. |
| 54 |
|
| 55 |
[[cockpit-metrics-fetch]] |
| 56 |
== metrics.fetch() |
| 57 |
|
| 58 |
.... |
| 59 |
metrics.fetch(beg, end) |
| 60 |
.... |
| 61 |
|
| 62 |
Retrieve archived metrics data between `+beg+` and `+end+`. The |
| 63 |
arguments can either be numbers, in which case they are interval based |
| 64 |
offsets, or they can be javascript Date objects. |
| 65 |
|
| 66 |
[[cockpit-metrics-follow]] |
| 67 |
== metrics.follow() |
| 68 |
|
| 69 |
.... |
| 70 |
metrics.follow() |
| 71 |
.... |
| 72 |
|
| 73 |
Start retrieving live metrics data as it become available. |
| 74 |
|
| 75 |
[[cockpit-metrics-close]] |
| 76 |
== metrics.close() |
| 77 |
|
| 78 |
.... |
| 79 |
metrics.close() |
| 80 |
.... |
| 81 |
|
| 82 |
Stop the retrieval of metrics and release resources. |
| 83 |
|
| 84 |
[[cockpit-metrics-series]] |
| 85 |
== metrics.series |
| 86 |
|
| 87 |
The series sink where data retrieved data will be processed. |
| 88 |
|
| 89 |
[[cockpit-metrics-meta]] |
| 90 |
== metrics.meta |
| 91 |
|
| 92 |
The metrics meta data last received. |
| 93 |
|
| 94 |
[[cockpit-metrics-onchanged]] |
| 95 |
== metrics.onchanged |
| 96 |
|
| 97 |
.... |
| 98 |
metrics.onchanged = function() { } |
| 99 |
.... |
| 100 |
|
| 101 |
An event triggered when one of the properties on this metrics object |
| 102 |
changes. |