allow filtering metrics sent to backends; fixes #2257
Costa Tsaousis (ktsaou) committed
Jun 9, 2017 at 02:06 UTC
6267958567f4e76c27030b7357af3de35decf03b
2 files changed
+26
-5
src/backends.c
+19
@@ -384,7 +384,23 @@ static inline int process_json_response(BUFFER *b) {
384
// ----------------------------------------------------------------------------
385
// the backend thread
386
387
+static SIMPLE_PATTERN *charts_pattern = NULL;
388
+
389
static inline int backends_can_send_rrdset(uint32_t options, RRDSET *st) {
390
+ if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_BACKEND_IGNORE)))
391
+ return 0;
392
+
393
+ if(unlikely(!rrdset_flag_check(st, RRDSET_FLAG_BACKEND_SEND))) {
394
+ // we have not checked this chart
395
+ if(simple_pattern_matches(charts_pattern, st->id) || simple_pattern_matches(charts_pattern, st->name))
396
+ rrdset_flag_set(st, RRDSET_FLAG_BACKEND_SEND);
397
+ else {
398
+ rrdset_flag_set(st, RRDSET_FLAG_BACKEND_IGNORE);
399
+ debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is disabled for backends.", st->id, st->rrdhost->hostname);
400
+ return 0;
401
+ }
402
+ }
403
+
404
if(unlikely(!rrdset_is_available_for_backends(st))) {
405
debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is not available for backends.", st->id, st->rrdhost->hostname);
406
return 0;
@@ -433,6 +449,9 @@ void *backends_main(void *ptr) {
449
int buffer_on_failures = (int)config_get_number(CONFIG_SECTION_BACKEND, "buffer on failures", 10);
450
long timeoutms = config_get_number(CONFIG_SECTION_BACKEND, "timeout ms", frequency * 2 * 1000);
451
452
+ charts_pattern = simple_pattern_create(config_get(CONFIG_SECTION_BACKEND, "send charts matching", "*"), SIMPLE_PATTERN_EXACT);
453
+
454
+
455
// ------------------------------------------------------------------------
456
// validate configuration options
457
// and prepare for sending data to our backend
src/rrd.h
+7
-5
@@ -212,11 +212,13 @@ typedef struct rrddim RRDDIM;
212
// and may lead to missing information.
213
214
typedef enum rrdset_flags {
215
- RRDSET_FLAG_ENABLED = 1 << 0, // enables or disables a chart
216
- RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
217
- // (the master data set should be the one that has the same family and is not detail)
218
- RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
219
- RRDSET_FLAG_OBSOLETE = 1 << 3 // this is marked by the collector/module as obsolete
215
+ RRDSET_FLAG_ENABLED = 1 << 0, // enables or disables a chart
216
+ RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
217
+ // (the master data set should be the one that has the same family and is not detail)
218
+ RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
219
+ RRDSET_FLAG_OBSOLETE = 1 << 3, // this is marked by the collector/module as obsolete
220
+ RRDSET_FLAG_BACKEND_SEND = 1 << 4,
221
+ RRDSET_FLAG_BACKEND_IGNORE = 1 << 5
222
} RRDSET_FLAGS;
223
224
#define rrdset_flag_check(st, flag) ((st)->flags & flag)