enhance the plugins protocol to support flags per chart; 2 flags added: "detail" and "obsolete"; enhance the streaming protocol to support these flags; fixes #2161, fixes #2222
Costa Tsaousis (ktsaou) committed
Jul 2, 2017 at 15:48 UTC
b448101d9aaf1be8c8202c056ac32a00a9d2b325
11 files changed
+84
-47
src/freebsd_devstat.c
+8
-8
@@ -74,21 +74,21 @@ static size_t disks_added = 0, disks_found = 0;
74
75
static void disk_free(struct disk *dm) {
76
if (likely(dm->st_io))
77
- rrdset_flag_set(dm->st_io, RRDSET_FLAG_OBSOLETE);
77
+ rrdset_is_obsolete(dm->st_io);
78
if (likely(dm->st_ops))
79
- rrdset_flag_set(dm->st_ops, RRDSET_FLAG_OBSOLETE);
79
+ rrdset_is_obsolete(dm->st_ops);
80
if (likely(dm->st_qops))
81
- rrdset_flag_set(dm->st_qops, RRDSET_FLAG_OBSOLETE);
81
+ rrdset_is_obsolete(dm->st_qops);
82
if (likely(dm->st_util))
83
- rrdset_flag_set(dm->st_util, RRDSET_FLAG_OBSOLETE);
83
+ rrdset_is_obsolete(dm->st_util);
84
if (likely(dm->st_iotime))
85
- rrdset_flag_set(dm->st_iotime, RRDSET_FLAG_OBSOLETE);
85
+ rrdset_is_obsolete(dm->st_iotime);
86
if (likely(dm->st_await))
87
- rrdset_flag_set(dm->st_await, RRDSET_FLAG_OBSOLETE);
87
+ rrdset_is_obsolete(dm->st_await);
88
if (likely(dm->st_avagsz))
89
- rrdset_flag_set(dm->st_avagsz, RRDSET_FLAG_OBSOLETE);
89
+ rrdset_is_obsolete(dm->st_avagsz);
90
if (likely(dm->st_svctm))
91
- rrdset_flag_set(dm->st_svctm, RRDSET_FLAG_OBSOLETE);
91
+ rrdset_is_obsolete(dm->st_svctm);
92
93
disks_added--;
94
freez(dm->name);
src/freebsd_getifaddrs.c
+5
-5
@@ -50,15 +50,15 @@ static size_t network_interfaces_added = 0, network_interfaces_found = 0;
50
51
static void network_interface_free(struct network_interface *ifm) {
52
if (likely(ifm->st_bandwidth))
53
- rrdset_flag_set(ifm->st_bandwidth, RRDSET_FLAG_OBSOLETE);
53
+ rrdset_is_obsolete(ifm->st_bandwidth);
54
if (likely(ifm->st_packets))
55
- rrdset_flag_set(ifm->st_packets, RRDSET_FLAG_OBSOLETE);
55
+ rrdset_is_obsolete(ifm->st_packets);
56
if (likely(ifm->st_errors))
57
- rrdset_flag_set(ifm->st_errors, RRDSET_FLAG_OBSOLETE);
57
+ rrdset_is_obsolete(ifm->st_errors);
58
if (likely(ifm->st_drops))
59
- rrdset_flag_set(ifm->st_drops, RRDSET_FLAG_OBSOLETE);
59
+ rrdset_is_obsolete(ifm->st_drops);
60
if (likely(ifm->st_events))
61
- rrdset_flag_set(ifm->st_events, RRDSET_FLAG_OBSOLETE);
61
+ rrdset_is_obsolete(ifm->st_events);
62
63
network_interfaces_added--;
64
freez(ifm->name);
src/freebsd_getmntinfo.c
+2
-2
@@ -37,9 +37,9 @@ static size_t mount_points_added = 0, mount_points_found = 0;
37
38
static void mount_point_free(struct mount_point *m) {
39
if (likely(m->st_space))
40
- rrdset_flag_set(m->st_space, RRDSET_FLAG_OBSOLETE);
40
+ rrdset_is_obsolete(m->st_space);
41
if (likely(m->st_inodes))
42
- rrdset_flag_set(m->st_inodes, RRDSET_FLAG_OBSOLETE);
42
+ rrdset_is_obsolete(m->st_inodes);
43
44
mount_points_added--;
45
freez(m->name);
src/plugin_proc_diskspace.c
+1
-1
@@ -45,7 +45,7 @@ struct mount_point_metadata {
45
46
static DICTIONARY *dict_mountpoints = NULL;
47
48
-#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE); st = NULL; } } while(st)
48
+#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_is_obsolete(st); st = NULL; } } while(st)
49
50
int mount_point_cleanup(void *entry, void *data) {
51
(void)data;
src/plugins_d.c
+13
@@ -237,6 +237,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
237
char *chart = words[7];
238
char *priority_s = words[8];
239
char *update_every_s = words[9];
240
+ char *options = words[10];
241
242
if(unlikely(!type || !*type || !id || !*id)) {
243
error("PLUGINSD: '%s' is requesting a CHART, without a type.id, on host '%s'. Disabling it.", cd->fullfilename, host->hostname);
@@ -274,6 +275,18 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
275
cd->update_every = update_every;
276
}
277
else debug(D_PLUGINSD, "PLUGINSD: Chart '%s' already exists. Not adding it again.", st->id);
278
+
279
+ if(options && *options) {
280
+ if(strstr(options, "obsolete"))
281
+ rrdset_is_obsolete(st);
282
+ else
283
+ rrdset_isnot_obsolete(st);
284
+
285
+ if(strstr(options, "detail"))
286
+ rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
287
+ else
288
+ rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
289
+ }
290
}
291
else if(likely(hash == DIMENSION_HASH && !strcmp(s, PLUGINSD_KEYWORD_DIMENSION))) {
292
char *id = words[1];
src/proc_diskstats.c
+1
-1
@@ -44,7 +44,7 @@ static struct disk {
44
struct disk *next;
45
} *disk_root = NULL;
46
47
-#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE); st = NULL; } } while(st)
47
+#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_is_obsolete(st); st = NULL; } } while(st)
48
49
static struct disk *get_disk(unsigned long major, unsigned long minor, char *disk) {
50
static char path_to_get_hw_sector_size[FILENAME_MAX + 1] = "";
src/proc_net_dev.c
+7
-7
@@ -73,13 +73,13 @@ static struct netdev *netdev_root = NULL, *netdev_last_used = NULL;
73
static size_t netdev_added = 0, netdev_found = 0;
74
75
static void netdev_free(struct netdev *d) {
76
- if(d->st_bandwidth) rrdset_flag_set(d->st_bandwidth, RRDSET_FLAG_OBSOLETE);
77
- if(d->st_packets) rrdset_flag_set(d->st_packets, RRDSET_FLAG_OBSOLETE);
78
- if(d->st_errors) rrdset_flag_set(d->st_errors, RRDSET_FLAG_OBSOLETE);
79
- if(d->st_drops) rrdset_flag_set(d->st_drops, RRDSET_FLAG_OBSOLETE);
80
- if(d->st_fifo) rrdset_flag_set(d->st_fifo, RRDSET_FLAG_OBSOLETE);
81
- if(d->st_compressed) rrdset_flag_set(d->st_compressed, RRDSET_FLAG_OBSOLETE);
82
- if(d->st_events) rrdset_flag_set(d->st_events, RRDSET_FLAG_OBSOLETE);
76
+ if(d->st_bandwidth) rrdset_is_obsolete(d->st_bandwidth);
77
+ if(d->st_packets) rrdset_is_obsolete(d->st_packets);
78
+ if(d->st_errors) rrdset_is_obsolete(d->st_errors);
79
+ if(d->st_drops) rrdset_is_obsolete(d->st_drops);
80
+ if(d->st_fifo) rrdset_is_obsolete(d->st_fifo);
81
+ if(d->st_compressed) rrdset_is_obsolete(d->st_compressed);
82
+ if(d->st_events) rrdset_is_obsolete(d->st_events);
83
84
netdev_added--;
85
freez(d->name);
src/rrd.h
+10
-6
@@ -218,13 +218,14 @@ typedef struct rrddim RRDDIM;
218
// and may lead to missing information.
219
220
typedef enum rrdset_flags {
221
- RRDSET_FLAG_ENABLED = 1 << 0, // enables or disables a chart
222
- RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
221
+ RRDSET_FLAG_ENABLED = 1 << 0, // enables or disables a chart
222
+ RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
223
// (the master data set should be the one that has the same family and is not detail)
224
- RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
225
- RRDSET_FLAG_OBSOLETE = 1 << 3, // this is marked by the collector/module as obsolete
226
- RRDSET_FLAG_BACKEND_SEND = 1 << 4,
227
- RRDSET_FLAG_BACKEND_IGNORE = 1 << 5
224
+ RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
225
+ RRDSET_FLAG_OBSOLETE = 1 << 3, // this is marked by the collector/module as obsolete
226
+ RRDSET_FLAG_BACKEND_SEND = 1 << 4, // if set, this chart should be sent to backends
227
+ RRDSET_FLAG_BACKEND_IGNORE = 1 << 5, // if set, this chart should not be sent to backends
228
+ RRDSET_FLAG_EXPOSED_UPSTREAM = 1 << 6 // if set, we have sent this chart to netdata master (streaming)
229
} RRDSET_FLAGS;
230
231
#ifdef HAVE_C___ATOMIC
@@ -600,6 +601,9 @@ extern void rrdset_next_usec(RRDSET *st, usec_t microseconds);
601
602
extern void rrdset_done(RRDSET *st);
603
604
+extern void rrdset_is_obsolete(RRDSET *st);
605
+extern void rrdset_isnot_obsolete(RRDSET *st);
606
+
607
// checks if the RRDSET should be offered to viewers
608
#define rrdset_is_available_for_viewers(st) (rrdset_flag_check(st, RRDSET_FLAG_ENABLED) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && (st)->dimensions && (st)->rrd_memory_mode != RRD_MEMORY_MODE_NONE)
609
#define rrdset_is_available_for_backends(st) (rrdset_flag_check(st, RRDSET_FLAG_ENABLED) && !rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && (st)->dimensions)
src/rrdpush.c
+7
-1
@@ -64,6 +64,9 @@ unsigned int remote_clock_resync_iterations = 60;
64
65
// checks if the current chart definition has been sent
66
static inline int need_to_send_chart_definition(RRDSET *st) {
67
+ if(unlikely(!(rrdset_flag_check(st, RRDSET_FLAG_EXPOSED_UPSTREAM))))
68
+ return 1;
69
+
70
RRDDIM *rd;
71
rrddim_foreach_read(rd, st)
72
if(!rd->exposed)
@@ -74,7 +77,7 @@ static inline int need_to_send_chart_definition(RRDSET *st) {
77
78
// sends the current chart definition
79
static inline void send_chart_definition(RRDSET *st) {
77
- buffer_sprintf(st->rrdhost->rrdpush_buffer, "CHART \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" %ld %d\n"
80
+ buffer_sprintf(st->rrdhost->rrdpush_buffer, "CHART \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" %ld %d \"%s %s\"\n"
81
, st->id
82
, st->name
83
, st->title
@@ -84,6 +87,8 @@ static inline void send_chart_definition(RRDSET *st) {
87
, rrdset_type_name(st->chart_type)
88
, st->priority
89
, st->update_every
90
+ , rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE)?"obsolete":""
91
+ , rrdset_flag_check(st, RRDSET_FLAG_DETAIL)?"detail":""
92
);
93
94
RRDDIM *rd;
@@ -101,6 +106,7 @@ static inline void send_chart_definition(RRDSET *st) {
106
}
107
108
st->upstream_resync_time = st->last_collected_time.tv_sec + (remote_clock_resync_iterations * st->update_every);
109
+ rrdset_flag_set(st, RRDSET_FLAG_EXPOSED_UPSTREAM);
110
}
111
112
// sends the current chart dimensions
src/rrdset.c
+16
-2
@@ -168,6 +168,19 @@ void rrdset_set_name(RRDSET *st, const char *name) {
168
error("RRDSET: INTERNAL ERROR: attempted to index duplicate chart name '%s'", st->name);
169
}
170
171
+inline void rrdset_is_obsolete(RRDSET *st) {
172
+ if(unlikely(!(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE)))) {
173
+ rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE);
174
+ rrdset_flag_clear(st, RRDSET_FLAG_EXPOSED_UPSTREAM);
175
+ }
176
+}
177
+
178
+inline void rrdset_isnot_obsolete(RRDSET *st) {
179
+ if(unlikely((rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE)))) {
180
+ rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
181
+ rrdset_flag_clear(st, RRDSET_FLAG_EXPOSED_UPSTREAM);
182
+ }
183
+}
184
185
// ----------------------------------------------------------------------------
186
// RRDSET - reset a chart
@@ -343,7 +356,7 @@ void rrdset_delete(RRDSET *st) {
356
static inline RRDSET *rrdset_find_on_create(RRDHOST *host, const char *fullid) {
357
RRDSET *st = rrdset_find(host, fullid);
358
if(unlikely(st)) {
346
- rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
359
+ rrdset_isnot_obsolete(st);
360
debug(D_RRD_CALLS, "RRDSET '%s', already exists.", fullid);
361
return st;
362
}
@@ -539,6 +552,7 @@ RRDSET *rrdset_create_custom(
552
rrdset_flag_clear(st, RRDSET_FLAG_DETAIL);
553
rrdset_flag_clear(st, RRDSET_FLAG_DEBUG);
554
rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
555
+ rrdset_flag_clear(st, RRDSET_FLAG_EXPOSED_UPSTREAM);
556
557
// if(!strcmp(st->id, "disk_util.dm-0")) {
558
// st->debug = 1;
@@ -954,7 +968,7 @@ void rrdset_done(RRDSET *st) {
968
969
if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE))) {
970
error("Chart '%s' has the OBSOLETE flag set, but it is collected.", st->id);
957
- rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
971
+ rrdset_isnot_obsolete(st);
972
}
973
974
// check if the chart has a long time to be updated
src/sys_fs_cgroup.c
+14
-14
@@ -901,20 +901,20 @@ static inline struct cgroup *cgroup_add(const char *id) {
901
static inline void cgroup_free(struct cgroup *cg) {
902
debug(D_CGROUP, "Removing cgroup '%s' with chart id '%s' (was %s and %s)", cg->id, cg->chart_id, (cg->enabled)?"enabled":"disabled", (cg->available)?"available":"not available");
903
904
- if(cg->st_cpu) rrdset_flag_set(cg->st_cpu, RRDSET_FLAG_OBSOLETE);
905
- if(cg->st_cpu_per_core) rrdset_flag_set(cg->st_cpu_per_core, RRDSET_FLAG_OBSOLETE);
906
- if(cg->st_mem) rrdset_flag_set(cg->st_mem, RRDSET_FLAG_OBSOLETE);
907
- if(cg->st_writeback) rrdset_flag_set(cg->st_writeback, RRDSET_FLAG_OBSOLETE);
908
- if(cg->st_mem_activity) rrdset_flag_set(cg->st_mem_activity, RRDSET_FLAG_OBSOLETE);
909
- if(cg->st_pgfaults) rrdset_flag_set(cg->st_pgfaults, RRDSET_FLAG_OBSOLETE);
910
- if(cg->st_mem_usage) rrdset_flag_set(cg->st_mem_usage, RRDSET_FLAG_OBSOLETE);
911
- if(cg->st_mem_failcnt) rrdset_flag_set(cg->st_mem_failcnt, RRDSET_FLAG_OBSOLETE);
912
- if(cg->st_io) rrdset_flag_set(cg->st_io, RRDSET_FLAG_OBSOLETE);
913
- if(cg->st_serviced_ops) rrdset_flag_set(cg->st_serviced_ops, RRDSET_FLAG_OBSOLETE);
914
- if(cg->st_throttle_io) rrdset_flag_set(cg->st_throttle_io, RRDSET_FLAG_OBSOLETE);
915
- if(cg->st_throttle_serviced_ops) rrdset_flag_set(cg->st_throttle_serviced_ops, RRDSET_FLAG_OBSOLETE);
916
- if(cg->st_queued_ops) rrdset_flag_set(cg->st_queued_ops, RRDSET_FLAG_OBSOLETE);
917
- if(cg->st_merged_ops) rrdset_flag_set(cg->st_merged_ops, RRDSET_FLAG_OBSOLETE);
904
+ if(cg->st_cpu) rrdset_is_obsolete(cg->st_cpu);
905
+ if(cg->st_cpu_per_core) rrdset_is_obsolete(cg->st_cpu_per_core);
906
+ if(cg->st_mem) rrdset_is_obsolete(cg->st_mem);
907
+ if(cg->st_writeback) rrdset_is_obsolete(cg->st_writeback);
908
+ if(cg->st_mem_activity) rrdset_is_obsolete(cg->st_mem_activity);
909
+ if(cg->st_pgfaults) rrdset_is_obsolete(cg->st_pgfaults);
910
+ if(cg->st_mem_usage) rrdset_is_obsolete(cg->st_mem_usage);
911
+ if(cg->st_mem_failcnt) rrdset_is_obsolete(cg->st_mem_failcnt);
912
+ if(cg->st_io) rrdset_is_obsolete(cg->st_io);
913
+ if(cg->st_serviced_ops) rrdset_is_obsolete(cg->st_serviced_ops);
914
+ if(cg->st_throttle_io) rrdset_is_obsolete(cg->st_throttle_io);
915
+ if(cg->st_throttle_serviced_ops) rrdset_is_obsolete(cg->st_throttle_serviced_ops);
916
+ if(cg->st_queued_ops) rrdset_is_obsolete(cg->st_queued_ops);
917
+ if(cg->st_merged_ops) rrdset_is_obsolete(cg->st_merged_ops);
918
919
freez(cg->cpuacct_usage.cpu_percpu);
920