filter backends by hostname; fixes #3316
Costa Tsaousis (ktsaou) committed
Jan 20, 2018 at 16:23 UTC
7bff304980a6a268be6dfee9c15d5738280fa425
3 files changed
+26
-6
src/apps_plugin.c
+1
-1
@@ -2008,7 +2008,7 @@ static inline void link_all_processes_to_their_parents(void) {
2008
// to avoid filling up all disk space
2009
// if debug is enabled, all errors are printed
2010
2011
-#ifndef __FreeBSD__
2011
+#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
2012
static int compar_pid(const void *pid1, const void *pid2) {
2013
2014
struct pid_stat *p1 = all_pids[*((pid_t *)pid1)];
src/backends.c
+17
@@ -447,6 +447,7 @@ static inline int process_json_response(BUFFER *b) {
447
// the backend thread
448
449
static SIMPLE_PATTERN *charts_pattern = NULL;
450
+static SIMPLE_PATTERN *hosts_pattern = NULL;
451
452
inline int backends_can_send_rrdset(uint32_t options, RRDSET *st) {
453
RRDHOST *host = st->rrdhost;
@@ -535,6 +536,7 @@ void *backends_main(void *ptr) {
536
backend_send_names = config_get_boolean(CONFIG_SECTION_BACKEND, "send names instead of ids", backend_send_names);
537
538
charts_pattern = simple_pattern_create(config_get(CONFIG_SECTION_BACKEND, "send charts matching", "*"), NULL, SIMPLE_PATTERN_EXACT);
539
+ hosts_pattern = simple_pattern_create(config_get(CONFIG_SECTION_BACKEND, "send hosts matching", "localhost *"), NULL, SIMPLE_PATTERN_EXACT);
540
541
542
// ------------------------------------------------------------------------
@@ -686,6 +688,21 @@ void *backends_main(void *ptr) {
688
rrd_rdlock();
689
RRDHOST *host;
690
rrdhost_foreach_read(host) {
691
+ if(unlikely(!rrdhost_flag_check(host, RRDHOST_FLAG_BACKEND_SEND|RRDHOST_FLAG_BACKEND_DONT_SEND))) {
692
+ char *name = (host == localhost)?"localhost":host->hostname;
693
+ if (!hosts_pattern || simple_pattern_matches(hosts_pattern, name)) {
694
+ rrdhost_flag_set(host, RRDHOST_FLAG_BACKEND_SEND);
695
+ info("enabled backend for host '%s'", name);
696
+ }
697
+ else {
698
+ rrdhost_flag_set(host, RRDHOST_FLAG_BACKEND_DONT_SEND);
699
+ info("disabled backend for host '%s'", name);
700
+ }
701
+ }
702
+
703
+ if(unlikely(!rrdhost_flag_check(host, RRDHOST_FLAG_BACKEND_SEND)))
704
+ continue;
705
+
706
rrdhost_rdlock(host);
707
708
count_hosts++;
src/rrd.h
+8
-5
@@ -19,6 +19,8 @@ extern int gap_when_lost_iterations_above;
19
typedef long long total_number;
20
#define TOTAL_NUMBER_FORMAT "%lld"
21
22
+typedef struct rrdhost RRDHOST;
23
+
24
// ----------------------------------------------------------------------------
25
// chart types
26
@@ -234,7 +236,7 @@ typedef enum rrdset_flags {
236
} RRDSET_FLAGS;
237
238
#ifdef HAVE_C___ATOMIC
237
-#define rrdset_flag_check(st, flag) (__atomic_load_n(&((st)->flags), __ATOMIC_SEQ_CST) & flag)
239
+#define rrdset_flag_check(st, flag) (__atomic_load_n(&((st)->flags), __ATOMIC_SEQ_CST) & (flag))
240
#define rrdset_flag_set(st, flag) __atomic_or_fetch(&((st)->flags), flag, __ATOMIC_SEQ_CST)
241
#define rrdset_flag_clear(st, flag) __atomic_and_fetch(&((st)->flags), ~flag, __ATOMIC_SEQ_CST)
242
#else
@@ -322,7 +324,7 @@ struct rrdset {
324
total_number last_collected_total; // used internally to calculate percentages
325
326
RRDFAMILY *rrdfamily; // pointer to RRDFAMILY this chart belongs to
325
- struct rrdhost *rrdhost; // pointer to RRDHOST this chart belongs to
327
+ RRDHOST *rrdhost; // pointer to RRDHOST this chart belongs to
328
329
struct rrdset *next; // linking of rrdsets
330
@@ -376,11 +378,13 @@ typedef struct rrdset RRDSET;
378
typedef enum rrdhost_flags {
379
RRDHOST_FLAG_ORPHAN = 1 << 0, // this host is orphan (not receiving data)
380
RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS = 1 << 1, // delete files of obsolete charts
379
- RRDHOST_FLAG_DELETE_ORPHAN_HOST = 1 << 2 // delete the entire host when orphan
381
+ RRDHOST_FLAG_DELETE_ORPHAN_HOST = 1 << 2, // delete the entire host when orphan
382
+ RRDHOST_FLAG_BACKEND_SEND = 1 << 3, // send it to backends
383
+ RRDHOST_FLAG_BACKEND_DONT_SEND = 1 << 4, // don't send it to backends
384
} RRDHOST_FLAGS;
385
386
#ifdef HAVE_C___ATOMIC
383
-#define rrdhost_flag_check(host, flag) (__atomic_load_n(&((host)->flags), __ATOMIC_SEQ_CST) & flag)
387
+#define rrdhost_flag_check(host, flag) (__atomic_load_n(&((host)->flags), __ATOMIC_SEQ_CST) & (flag))
388
#define rrdhost_flag_set(host, flag) __atomic_or_fetch(&((host)->flags), flag, __ATOMIC_SEQ_CST)
389
#define rrdhost_flag_clear(host, flag) __atomic_and_fetch(&((host)->flags), ~flag, __ATOMIC_SEQ_CST)
390
#else
@@ -510,7 +514,6 @@ struct rrdhost {
514
515
struct rrdhost *next;
516
};
513
-typedef struct rrdhost RRDHOST;
517
extern RRDHOST *localhost;
518
519
#define rrdhost_rdlock(host) netdata_rwlock_rdlock(&((host)->rrdhost_rwlock))