@cryptotaxi247 / netdata-1 / commits / 5a718bb8b

Stop multi-host DB statistics from being counted multiple times. (#9685)

Markos Fountoulakis committed Aug 7, 2020 at 11:28 UTC 5a718bb8b02eef930b41ef1f79873d93c2d38248
1 file changed +10 -5
daemon/global_statistics.c
+10 -5
@@ -537,12 +537,17 @@ void global_statistics_charts(void) {
537 RRDHOST *host;
538 unsigned long long stats_array[RRDENG_NR_STATS] = {0};
539 unsigned long long local_stats_array[RRDENG_NR_STATS];
540 - unsigned hosts_with_dbengine = 0, i;
540 + unsigned dbengine_contexts = 0, counted_multihost_db = 0, i;
541
542 rrd_rdlock();
543 rrdhost_foreach_read(host) {
544 - if (host->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
545 - ++hosts_with_dbengine;
544 + if (host->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE && !rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED)) {
545 + if (&multidb_ctx == host->rrdeng_ctx) {
546 + if (counted_multihost_db)
547 + continue; /* Only count multi-host DB once */
548 + counted_multihost_db = 1;
549 + }
550 + ++dbengine_contexts;
551 /* get localhost's DB engine's statistics */
552 rrdeng_get_37_statistics(host->rrdeng_ctx, local_stats_array);
553 for (i = 0 ; i < RRDENG_NR_STATS ; ++i) {
@@ -553,8 +558,8 @@ void global_statistics_charts(void) {
558 }
559 rrd_unlock();
560
556 - if (hosts_with_dbengine) {
557 - /* deduplicate global statistics by getting the ones from the last host */
561 + if (dbengine_contexts) {
562 + /* deduplicate global statistics by getting the ones from the last context */
563 stats_array[30] = local_stats_array[30];
564 stats_array[31] = local_stats_array[31];
565 stats_array[32] = local_stats_array[32];