| 1 |
= cockpit.js: Series Data |
| 2 |
|
| 3 |
Series data consists of values along a continuous (usually time) axis. |
| 4 |
We can place these in grids which expose a distinct subset of these |
| 5 |
values. These are the underlying mechanism for displaying metrics data |
| 6 |
in graphs. |
| 7 |
|
| 8 |
[[cockpit-grid]] |
| 9 |
== cockpit.grid() |
| 10 |
|
| 11 |
.... |
| 12 |
grid = cockpit.grid(interval, [beg, end]) |
| 13 |
.... |
| 14 |
|
| 15 |
Creates a grid object to contain series data. |
| 16 |
|
| 17 |
The `+interval+` is the granularity of the grid. Usually this is a |
| 18 |
number of milliseconds, when used with time series data. The `+beg+` and |
| 19 |
`+end+` are the bounds of the grid. If omitted they will be set to zero |
| 20 |
for an initially empty grid. |
| 21 |
|
| 22 |
If `+beg+` and/or `+end+` are negative (including negative zero) then |
| 23 |
they are interpreted in number of intervals relative to the current |
| 24 |
time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most |
| 25 |
recent 5 minutes. |
| 26 |
|
| 27 |
[[cockpit-grid-add]] |
| 28 |
== grid.add() |
| 29 |
|
| 30 |
.... |
| 31 |
row = grid.add(series, path) |
| 32 |
row = grid.add(callback, [early]) |
| 33 |
row = grid.add() |
| 34 |
.... |
| 35 |
|
| 36 |
Adds a row to the grid. The returned `+row+` is a Javascript array that |
| 37 |
will contain series data. The arguments control how the row is populated |
| 38 |
from the series data. The `+row+` is a sparse array. Its `+row.length+` |
| 39 |
will not match the expected size of the grid, unless and until the row |
| 40 |
has been completely filled in. The first index of the `+row+` will |
| 41 |
contain the data from the series data at the |
| 42 |
link:#cockpit-grid-beg[`+grid.beg+`] offset. |
| 43 |
|
| 44 |
When no arguments are passed, an empty row is added, and it is not |
| 45 |
populated with data. |
| 46 |
|
| 47 |
When called with a `+series+` and `+path+` argument then the row will be |
| 48 |
populated directly with series data. The `+series+` can either be a |
| 49 |
link:#cockpit-series[series object] or an object that has an |
| 50 |
`+obj.series+` property. The link:#cockpit-series-interval[series |
| 51 |
interval] must match the interval of this grid. If `+path+` is missing |
| 52 |
or empty, then the series data is placed into the row directly. |
| 53 |
Otherwise `+path+` indicates which part of the series data to place in |
| 54 |
the row. When `+path+` is an array, it is used as a set of property |
| 55 |
names or array indexes to follow into nested series data. When `+path+` |
| 56 |
is a dotted string, it is split and used the same way to locate the |
| 57 |
correct value in nested series data. The exact format of the series data |
| 58 |
depends on its producer, and relevant paths will be documented there. |
| 59 |
|
| 60 |
If a `+callback+` function is specified, then it will be invoked to |
| 61 |
provide series data for the row. The function is invoked as |
| 62 |
`+callback(row, index, count)+`, where the `+row+` is the row to fill |
| 63 |
in, the `+index+` is the index to start filling in and `+count+` is the |
| 64 |
number of items to fill in. The `+this+` variable will be set to the |
| 65 |
grid while invoking the `+callback+`. The callback is called after other |
| 66 |
data rows for a given series have been filled in. Callbacks are called |
| 67 |
in the order added, unless the `+early+` argument is set to `+true+`, in |
| 68 |
which case the callback is called earlier than callbacks without the |
| 69 |
`+early+` argument set. |
| 70 |
|
| 71 |
To remove the row use the link:#cockpit-grid-remove[`+grid.remove()+` |
| 72 |
method.] |
| 73 |
|
| 74 |
The row will start being populated with data when the `+series+` |
| 75 |
produces data. To make this happen right away, use the |
| 76 |
link:#cockpit-grid-sync[`+grid.sync()+`] method. |
| 77 |
|
| 78 |
[[cockpit-grid-remove]] |
| 79 |
== grid.remove() |
| 80 |
|
| 81 |
.... |
| 82 |
grid.remove(row) |
| 83 |
.... |
| 84 |
|
| 85 |
Remove a previously added `+row+` from the grid. The row will no longer |
| 86 |
be updated with series data. |
| 87 |
|
| 88 |
[[cockpit-grid-sync]] |
| 89 |
== grid.sync() |
| 90 |
|
| 91 |
.... |
| 92 |
grid.sync() |
| 93 |
.... |
| 94 |
|
| 95 |
Load or reload data from the series into the rows. This does not clear |
| 96 |
the rows before populating them. Some data may be populated immediately, |
| 97 |
others may have to wait until data can be loaded. Internally this |
| 98 |
function calls link:#cockpit-series-load[`+series.load()+`] for each |
| 99 |
series. |
| 100 |
|
| 101 |
All rows with callbacks will be invoked to regenerate all the data. The |
| 102 |
link:#cockpit-grid-onnotify[`+grid.onnotify+`] event will be triggered. |
| 103 |
It is not necessary to call this function after a call of the |
| 104 |
link:#cockpit-grid-move[`+grid.move()+`] method. |
| 105 |
|
| 106 |
[[cockpit-grid-move]] |
| 107 |
== grid.move() |
| 108 |
|
| 109 |
.... |
| 110 |
grid.move(beg[, end]) |
| 111 |
.... |
| 112 |
|
| 113 |
Move the grid to new `+beg+` and `+end+` range. Data will be discarded |
| 114 |
from the rows and link:#cockpit-grid-sync[`+grid.sync()+`] will be |
| 115 |
called to load or reload series data for the new range of offsets. |
| 116 |
|
| 117 |
If `+end+` is not specified it will be set to `+beg+`. If `+beg+` and/or |
| 118 |
`+end+` are negative (including negative zero) then they will be set to |
| 119 |
the number of intervals prior to the current time taken as an interval. |
| 120 |
|
| 121 |
If `+beg+` and/or `+end+` are negative (including negative zero) then |
| 122 |
they are interpreted in number of intervals relative to the current |
| 123 |
time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most |
| 124 |
recent 5 minutes. |
| 125 |
|
| 126 |
[[cockpit-grid-walk]] |
| 127 |
== grid.walk() |
| 128 |
|
| 129 |
.... |
| 130 |
grid.walk() |
| 131 |
.... |
| 132 |
|
| 133 |
Move the grid forward every |
| 134 |
link:#cockpit-grid-interval[`+grid.interval+`] milliseconds. To stop |
| 135 |
moving forward, call link:#cockpit-grid-move[`+grid.move()+`]. |
| 136 |
|
| 137 |
[[cockpit-grid-notify]] |
| 138 |
== grid.notify() |
| 139 |
|
| 140 |
.... |
| 141 |
grid.notify(index, count) |
| 142 |
.... |
| 143 |
|
| 144 |
This function is called to have rows with callbacks recalculate their |
| 145 |
data. It is not normally necessary to call this function, as it will be |
| 146 |
invoked automatically when new series data is available or has been |
| 147 |
loaded. This function triggers the |
| 148 |
link:#cockpit-grid-onnotify[`+grid.onnotify+`] event. |
| 149 |
|
| 150 |
[[cockpit-grid-onnotify]] |
| 151 |
== grid.onnotify |
| 152 |
|
| 153 |
.... |
| 154 |
grid.addEventListener("notify", function(index, count) { ... }); |
| 155 |
.... |
| 156 |
|
| 157 |
An event that is triggered when some part of the series data in grid |
| 158 |
changes. The `+index+` is the row index where things changed, and the |
| 159 |
`+count+` is the length of the data that changed. |
| 160 |
|
| 161 |
[[cockpit-grid-close]] |
| 162 |
== grid.close() |
| 163 |
|
| 164 |
.... |
| 165 |
grid.close() |
| 166 |
.... |
| 167 |
|
| 168 |
Close the grid, and stop updating the rows. |
| 169 |
|
| 170 |
[[cockpit-grid-interval]] |
| 171 |
== grid.interval |
| 172 |
|
| 173 |
The granularity of the grid. For time series data this is an interval in |
| 174 |
milliseconds. In order to use a given link:#cockpit-grid[grid] and |
| 175 |
link:#cockpit-series[series] together, their interval properties must |
| 176 |
match. |
| 177 |
|
| 178 |
[[cockpit-grid-beg]] |
| 179 |
== grid.beg |
| 180 |
|
| 181 |
The beginning offset of the series data in the grid. Do not set this |
| 182 |
property directly. Use the link:#cockpit-grid-move[grid.move()] method |
| 183 |
instead. |
| 184 |
|
| 185 |
[[cockpit-grid-end]] |
| 186 |
== grid.end |
| 187 |
|
| 188 |
The ending offset of the series data in the grid. Do not set this |
| 189 |
property directly. Use the link:#cockpit-grid-move[grid.move()] method |
| 190 |
instead. |
| 191 |
|
| 192 |
[[cockpit-series]] |
| 193 |
== cockpit.series() |
| 194 |
|
| 195 |
.... |
| 196 |
series = cockpit.series(interval, [cache, fetch]) |
| 197 |
.... |
| 198 |
|
| 199 |
Create a new sink of series data. This is usually done by producers of |
| 200 |
series data, and it is rare to invoke this function directly. |
| 201 |
|
| 202 |
The `+interval+` is the granularity of the series data. For time series |
| 203 |
data this is an interval in milliseconds. If a `+cache+` string is |
| 204 |
specified, series data will be cached across frames for series with the |
| 205 |
same `+cache+` cache identifier to load and/or reload. |
| 206 |
|
| 207 |
If a `+fetch+` callback is specified, then it will be invoked when grids |
| 208 |
request certain ranges of data. The `+fetch+` callback is invoked with |
| 209 |
`+function fetch(beg, end) { ... }+` range offsets. The |
| 210 |
link:#cockpit-series-input[series.input()] should be called with data |
| 211 |
retrieved, either immediately or at a later time. The callback may be |
| 212 |
called multiple times for the same ranges of data. It is up to the |
| 213 |
callback to determine when or whether it should retrieve the data more |
| 214 |
than once. |
| 215 |
|
| 216 |
A producer of series data, usually calls this function and creates |
| 217 |
itself a `+obj.series+` property containing this series object. |
| 218 |
|
| 219 |
[[cockpit-series-input]] |
| 220 |
== series.input() |
| 221 |
|
| 222 |
.... |
| 223 |
series.input(beg, items[, mapping]) |
| 224 |
.... |
| 225 |
|
| 226 |
Send series data into the series sink. Any grids that have added rows |
| 227 |
based on this series, will have data filled in. The `+beg+` is the |
| 228 |
beginning offset of `+items+`. The `+items+` are an array one or more |
| 229 |
series data items. |
| 230 |
|
| 231 |
Producers may wish to provide additional properties that can be used in |
| 232 |
lookup paths that rows can pull from. This is done in the `+mapping+` |
| 233 |
argument. If specified it is a tree of objects. Each sub object should |
| 234 |
have a property with the name `+""+` empty string, which will be used as |
| 235 |
the property name or index in place of the one used in the lookup path. |
| 236 |
|
| 237 |
[[cockpit-series-load]] |
| 238 |
== series.load() |
| 239 |
|
| 240 |
.... |
| 241 |
series.load(beg, end) |
| 242 |
.... |
| 243 |
|
| 244 |
Load data from the series into any grids that have rows based on this |
| 245 |
series data. Any cached data will be filled in immediately. Any data not |
| 246 |
cached, will be requested from the producer, if possible, and may arrive |
| 247 |
at a later time. |
| 248 |
|
| 249 |
The `+beg+` and `+end+` denote the range of data to load. |
| 250 |
|
| 251 |
[[cockpit-series-interval]] |
| 252 |
== series.interval |
| 253 |
|
| 254 |
The granularity of the series. For time series data this is an interval |
| 255 |
in milliseconds. In order to use a given link:#cockpit-grid[grid] and |
| 256 |
link:#cockpit-series[series] together, their interval properties must |
| 257 |
match. |
| 258 |
|
| 259 |
[[cockpit-series-limit]] |
| 260 |
== series.limit |
| 261 |
|
| 262 |
The maximum number of items to cache for loading and/or reloading. You |
| 263 |
can change this value to a different number. Having a number close to |
| 264 |
zero will break certain usage of grids, such as |
| 265 |
link:#cockpit-grid-walk[`+grid.walk()+`]. |