1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef NETDATA_RRDCONTEXT_H
#define NETDATA_RRDCONTEXT_H 1
// ----------------------------------------------------------------------------
// RRDMETRIC
typedef struct rrdmetric_acquired RRDMETRIC_ACQUIRED;
// ----------------------------------------------------------------------------
// RRDINSTANCE
typedef struct rrdinstance_acquired RRDINSTANCE_ACQUIRED;
// ----------------------------------------------------------------------------
// RRDCONTEXT
typedef struct rrdcontext_acquired RRDCONTEXT_ACQUIRED;
// ----------------------------------------------------------------------------
#include "../rrd.h"
bool rrdinstance_acquired_id_and_name_are_same(RRDINSTANCE_ACQUIRED *ria);
const char *rrdmetric_acquired_id(RRDMETRIC_ACQUIRED *rma);
const char *rrdmetric_acquired_name(RRDMETRIC_ACQUIRED *rma);
bool rrdmetric_acquired_has_name(RRDMETRIC_ACQUIRED *rma);
STRING *rrdmetric_acquired_id_dup(RRDMETRIC_ACQUIRED *rma);
STRING *rrdmetric_acquired_name_dup(RRDMETRIC_ACQUIRED *rma);
NETDATA_DOUBLE rrdmetric_acquired_last_stored_value(RRDMETRIC_ACQUIRED *rma);
time_t rrdmetric_acquired_first_entry(RRDMETRIC_ACQUIRED *rma);
time_t rrdmetric_acquired_last_entry(RRDMETRIC_ACQUIRED *rma);
bool rrdmetric_acquired_belongs_to_instance(RRDMETRIC_ACQUIRED *rma, RRDINSTANCE_ACQUIRED *ria);
const char *rrdinstance_acquired_id(RRDINSTANCE_ACQUIRED *ria);
const char *rrdinstance_acquired_name(RRDINSTANCE_ACQUIRED *ria);
bool rrdinstance_acquired_has_name(RRDINSTANCE_ACQUIRED *ria);
const char *rrdinstance_acquired_units(RRDINSTANCE_ACQUIRED *ria);
STRING *rrdinstance_acquired_units_dup(RRDINSTANCE_ACQUIRED *ria);
DICTIONARY *rrdinstance_acquired_labels(RRDINSTANCE_ACQUIRED *ria);
DICTIONARY *rrdinstance_acquired_functions(RRDINSTANCE_ACQUIRED *ria);
RRDHOST *rrdinstance_acquired_rrdhost(RRDINSTANCE_ACQUIRED *ria);
RRDSET *rrdinstance_acquired_rrdset(RRDINSTANCE_ACQUIRED *ria);
bool rrdinstance_acquired_belongs_to_context(RRDINSTANCE_ACQUIRED *ria, RRDCONTEXT_ACQUIRED *rca);
time_t rrdinstance_acquired_update_every(RRDINSTANCE_ACQUIRED *ria);
const char *rrdcontext_acquired_units(RRDCONTEXT_ACQUIRED *rca);
const char *rrdcontext_acquired_title(RRDCONTEXT_ACQUIRED *rca);
RRDSET_TYPE rrdcontext_acquired_chart_type(RRDCONTEXT_ACQUIRED *rca);
// ----------------------------------------------------------------------------
// public API for rrdhost
void rrdhost_load_rrdcontext_data(RRDHOST *host);
void rrdhost_create_rrdcontexts(RRDHOST *host);
void rrdhost_destroy_rrdcontexts(RRDHOST *host);
void rrdcontext_host_child_connected(RRDHOST *host);
void rrdcontext_host_child_disconnected(RRDHOST *host);
int rrdcontext_foreach_instance_with_rrdset_in_context(RRDHOST *host, const char *context, int (*callback)(RRDSET *st, void *data), void *data);
typedef enum {
RRDCONTEXT_OPTION_NONE = 0,
RRDCONTEXT_OPTION_SHOW_METRICS = (1 << 0),
RRDCONTEXT_OPTION_SHOW_INSTANCES = (1 << 1),
RRDCONTEXT_OPTION_SHOW_LABELS = (1 << 2),
RRDCONTEXT_OPTION_SHOW_QUEUED = (1 << 3),
RRDCONTEXT_OPTION_SHOW_FLAGS = (1 << 4),
RRDCONTEXT_OPTION_SHOW_DELETED = (1 << 5),
RRDCONTEXT_OPTION_DEEPSCAN = (1 << 6),
RRDCONTEXT_OPTION_SHOW_UUIDS = (1 << 7),
RRDCONTEXT_OPTION_SHOW_HIDDEN = (1 << 8),
RRDCONTEXT_OPTION_SKIP_ID = (1 << 31), // internal use
} RRDCONTEXT_TO_JSON_OPTIONS;
#define RRDCONTEXT_OPTIONS_ALL (RRDCONTEXT_OPTION_SHOW_METRICS|RRDCONTEXT_OPTION_SHOW_INSTANCES|RRDCONTEXT_OPTION_SHOW_LABELS|RRDCONTEXT_OPTION_SHOW_QUEUED|RRDCONTEXT_OPTION_SHOW_FLAGS|RRDCONTEXT_OPTION_SHOW_DELETED|RRDCONTEXT_OPTION_SHOW_UUIDS|RRDCONTEXT_OPTION_SHOW_HIDDEN)
int rrdcontext_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, RRDCONTEXT_TO_JSON_OPTIONS options, const char *context, SIMPLE_PATTERN *chart_label_key, SIMPLE_PATTERN *chart_labels_filter, SIMPLE_PATTERN *chart_dimensions);
int rrdcontexts_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, RRDCONTEXT_TO_JSON_OPTIONS options, SIMPLE_PATTERN *chart_label_key, SIMPLE_PATTERN *chart_labels_filter, SIMPLE_PATTERN *chart_dimensions);
// ----------------------------------------------------------------------------
// public API for rrdcontexts
const char *rrdcontext_acquired_id(RRDCONTEXT_ACQUIRED *rca);
bool rrdcontext_acquired_belongs_to_host(RRDCONTEXT_ACQUIRED *rca, RRDHOST *host);
// ----------------------------------------------------------------------------
// public API for rrddims
void rrdcontext_updated_rrddim(RRDDIM *rd);
void rrdcontext_removed_rrddim(RRDDIM *rd);
void rrdcontext_updated_rrddim_algorithm(RRDDIM *rd);
void rrdcontext_updated_rrddim_multiplier(RRDDIM *rd);
void rrdcontext_updated_rrddim_divisor(RRDDIM *rd);
void rrdcontext_updated_rrddim_flags(RRDDIM *rd);
void rrdcontext_collected_rrddim(RRDDIM *rd);
int rrdcontext_find_dimension_uuid(RRDSET *st, const char *id, uuid_t *store_uuid);
// ----------------------------------------------------------------------------
// public API for rrdsets
void rrdcontext_updated_rrdset(RRDSET *st);
void rrdcontext_removed_rrdset(RRDSET *st);
void rrdcontext_updated_rrdset_name(RRDSET *st);
void rrdcontext_updated_rrdset_flags(RRDSET *st);
void rrdcontext_updated_retention_rrdset(RRDSET *st);
void rrdcontext_collected_rrdset(RRDSET *st);
int rrdcontext_find_chart_uuid(RRDSET *st, uuid_t *store_uuid);
// ----------------------------------------------------------------------------
// public API for ACLK
void rrdcontext_hub_checkpoint_command(void *cmd);
void rrdcontext_hub_stop_streaming_command(void *cmd);
// ----------------------------------------------------------------------------
// public API for threads
void rrdcontext_db_rotation(void);
void *rrdcontext_main(void *);
// ----------------------------------------------------------------------------
// public API for queries
typedef enum __attribute__ ((__packed__)) {
QUERY_STATUS_NONE = 0,
QUERY_STATUS_QUERIED = (1 << 0),
QUERY_STATUS_DIMENSION_HIDDEN = (1 << 1),
QUERY_STATUS_EXCLUDED = (1 << 2),
QUERY_STATUS_FAILED = (1 << 3),
} QUERY_STATUS;
typedef struct query_plan_entry {
size_t tier;
time_t after;
time_t before;
} QUERY_PLAN_ENTRY;
#define QUERY_PLANS_MAX (RRD_STORAGE_TIERS)
typedef struct query_metrics_counts { // counts the number of metrics related to an object
size_t selected; // selected to be queried
size_t excluded; // not selected to be queried
size_t queried; // successfully queried
size_t failed; // failed to be queried
} QUERY_METRICS_COUNTS;
typedef struct query_instances_counts { // counts the number of instances related to an object
size_t selected; // selected to be queried
size_t excluded; // not selected to be queried
size_t queried; // successfully queried
size_t failed; // failed to be queried
} QUERY_INSTANCES_COUNTS;
typedef struct query_alerts_counts { // counts the number of alerts related to an object
size_t clear; // number of alerts in clear state
size_t warning; // number of alerts in warning state
size_t critical; // number of alerts in critical state
size_t other; // number of alerts in any other state
} QUERY_ALERTS_COUNTS;
typedef struct query_node {
uint32_t slot;
RRDHOST *rrdhost;
char node_id[UUID_STR_LEN];
usec_t duration_ut;
STORAGE_POINT query_points;
QUERY_INSTANCES_COUNTS instances;
QUERY_METRICS_COUNTS metrics;
QUERY_ALERTS_COUNTS alerts;
} QUERY_NODE;
typedef struct query_context {
uint32_t slot;
RRDCONTEXT_ACQUIRED *rca;
STORAGE_POINT query_points;
QUERY_INSTANCES_COUNTS instances;
QUERY_METRICS_COUNTS metrics;
|