1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
-#define NETDATA_RRD_INTERNALS
3
#include "rrd.h"
4
5
static void rrdhost_streaming_sender_structures_init(RRDHOST *host);
6
8
-bool dbengine_enabled = false; // will become true if and when dbengine is initialized
9
-size_t storage_tiers = 3;
10
-bool use_direct_io = true;
11
-size_t storage_tiers_grouping_iterations[RRD_STORAGE_TIERS] = { 1, 60, 60, 60, 60 };
12
-RRD_BACKFILL storage_tiers_backfill[RRD_STORAGE_TIERS] = { RRD_BACKFILL_NEW, RRD_BACKFILL_NEW, RRD_BACKFILL_NEW, RRD_BACKFILL_NEW, RRD_BACKFILL_NEW };
13
-
7
#if RRD_STORAGE_TIERS != 5
8
#error RRD_STORAGE_TIERS is not 5 - you need to update the grouping iterations per tier
9
#endif
10
11
size_t get_tier_grouping(size_t tier) {
19
- if(unlikely(tier >= storage_tiers)) tier = storage_tiers - 1;
12
+ if(unlikely(tier >= rrdb.storage_tiers)) tier = rrdb.storage_tiers - 1;
13
14
size_t grouping = 1;
15
// first tier is always 1 iteration of whatever update every the chart has
16
for(size_t i = 1; i <= tier ;i++)
24
- grouping *= storage_tiers_grouping_iterations[i];
17
+ grouping *= rrdb.storage_tiers_grouping_iterations[i];
18
19
return grouping;
20
}
21
29
-RRDHOST *localhost = NULL;
30
-netdata_rwlock_t rrd_rwlock = NETDATA_RWLOCK_INITIALIZER;
31
-
32
-time_t rrdset_free_obsolete_time_s = 3600;
33
-time_t rrdhost_free_orphan_time_s = 3600;
34
-
22
bool is_storage_engine_shared(STORAGE_INSTANCE *engine __maybe_unused) {
23
#ifdef ENABLE_DBENGINE
24
if(!rrdeng_is_legacy(engine))
28
return false;
29
}
30
44
-RRDHOST *find_host_by_node_id(char *node_id) {
45
-
31
+RRDHOST *rrdhost_find_by_node_id(const char *node_id) {
32
uuid_t node_uuid;
33
if (unlikely(!node_id || uuid_parse(node_id, node_uuid)))
34
return NULL;
35
36
RRDHOST *host, *ret = NULL;
51
- dfe_start_read(rrdhost_root_index, host) {
37
+ dfe_start_read(rrdb.rrdhost_root_index, host) {
38
if (host->node_id && !(uuid_memcmp(host->node_id, &node_uuid))) {
39
ret = host;
40
break;
48
// ----------------------------------------------------------------------------
49
// RRDHOST indexes management
50
65
-DICTIONARY *rrdhost_root_index = NULL;
66
-static DICTIONARY *rrdhost_root_index_hostname = NULL;
67
-
68
-static inline void rrdhost_init() {
69
- if(unlikely(!rrdhost_root_index)) {
70
- rrdhost_root_index = dictionary_create_advanced(
71
- DICT_OPTION_NAME_LINK_DONT_CLONE | DICT_OPTION_VALUE_LINK_DONT_CLONE | DICT_OPTION_DONT_OVERWRITE_VALUE,
72
- &dictionary_stats_category_rrdhost, 0);
73
- }
74
-
75
- if(unlikely(!rrdhost_root_index_hostname)) {
76
- rrdhost_root_index_hostname = dictionary_create_advanced(
77
- DICT_OPTION_NAME_LINK_DONT_CLONE | DICT_OPTION_VALUE_LINK_DONT_CLONE | DICT_OPTION_DONT_OVERWRITE_VALUE,
78
- &dictionary_stats_category_rrdhost, 0);
79
- }
80
-}
81
-
51
RRDHOST_ACQUIRED *rrdhost_find_and_acquire(const char *machine_guid) {
52
netdata_log_debug(D_RRD_CALLS, "rrdhost_find_and_acquire() host %s", machine_guid);
53
85
- return (RRDHOST_ACQUIRED *)dictionary_get_and_acquire_item(rrdhost_root_index, machine_guid);
54
+ return (RRDHOST_ACQUIRED *)dictionary_get_and_acquire_item(rrdb.rrdhost_root_index, machine_guid);
55
}
56
57
RRDHOST *rrdhost_acquired_to_rrdhost(RRDHOST_ACQUIRED *rha) {
65
if(unlikely(!rha))
66
return;
67
99
- dictionary_acquired_item_release(rrdhost_root_index, (const DICTIONARY_ITEM *)rha);
68
+ dictionary_acquired_item_release(rrdb.rrdhost_root_index, (const DICTIONARY_ITEM *)rha);
69
}
70
71
// ----------------------------------------------------------------------------
72
// RRDHOST index by UUID
73
74
inline size_t rrdhost_hosts_available(void) {
106
- return dictionary_entries(rrdhost_root_index);
75
+ return dictionary_entries(rrdb.rrdhost_root_index);
76
}
77
78
inline RRDHOST *rrdhost_find_by_guid(const char *guid) {
110
- return dictionary_get(rrdhost_root_index, guid);
79
+ return dictionary_get(rrdb.rrdhost_root_index, guid);
80
}
81
82
static inline RRDHOST *rrdhost_index_add_by_guid(RRDHOST *host) {
114
- RRDHOST *ret_machine_guid = dictionary_set(rrdhost_root_index, host->machine_guid, host, sizeof(RRDHOST));
83
+ RRDHOST *ret_machine_guid = dictionary_set(rrdb.rrdhost_root_index, host->machine_guid, host, sizeof(RRDHOST));
84
if(ret_machine_guid == host)
85
rrdhost_option_set(host, RRDHOST_OPTION_INDEXED_MACHINE_GUID);
86
else {
94
95
static void rrdhost_index_del_by_guid(RRDHOST *host) {
96
if(rrdhost_option_check(host, RRDHOST_OPTION_INDEXED_MACHINE_GUID)) {
128
- if(!dictionary_del(rrdhost_root_index, host->machine_guid))
97
+ if(!dictionary_del(rrdb.rrdhost_root_index, host->machine_guid))
98
netdata_log_error("RRDHOST: %s() failed to delete machine guid '%s' from index",
99
__FUNCTION__, host->machine_guid);
100
107
108
inline RRDHOST *rrdhost_find_by_hostname(const char *hostname) {
109
if(unlikely(!strcmp(hostname, "localhost")))
141
- return localhost;
110
+ return rrdb.localhost;
111
143
- return dictionary_get(rrdhost_root_index_hostname, hostname);
112
+ return dictionary_get(rrdb.rrdhost_root_index_hostname, hostname);
113
}
114
115
static inline void rrdhost_index_del_hostname(RRDHOST *host) {
116
if(unlikely(!host->hostname)) return;
117
118
if(rrdhost_option_check(host, RRDHOST_OPTION_INDEXED_HOSTNAME)) {
150
- if(!dictionary_del(rrdhost_root_index_hostname, rrdhost_hostname(host)))
119
+ if(!dictionary_del(rrdb.rrdhost_root_index_hostname, rrdhost_hostname(host)))
120
netdata_log_error("RRDHOST: %s() failed to delete hostname '%s' from index",
121
__FUNCTION__, rrdhost_hostname(host));
122
127
static inline RRDHOST *rrdhost_index_add_hostname(RRDHOST *host) {
128
if(!host->hostname) return host;
129
161
- RRDHOST *ret_hostname = dictionary_set(rrdhost_root_index_hostname, rrdhost_hostname(host), host, sizeof(RRDHOST));
130
+ RRDHOST *ret_hostname = dictionary_set(rrdb.rrdhost_root_index_hostname, rrdhost_hostname(host), host, sizeof(RRDHOST));
131
if(ret_hostname == host)
132
rrdhost_option_set(host, RRDHOST_OPTION_INDEXED_HOSTNAME);
133
else {
195
host->utc_offset = utc_offset;
196
}
197
229
-void set_host_properties(RRDHOST *host, int update_every, RRD_MEMORY_MODE memory_mode,
198
+void set_host_properties(RRDHOST *host, int update_every, STORAGE_ENGINE_ID storage_engine_id,
199
const char *registry_hostname, const char *os, const char *tags,
200
const char *tzone, const char *abbrev_tzone, int32_t utc_offset, const char *program_name,
201
const char *program_version)
202
{
203
235
- host->rrd_update_every = update_every;
236
- host->rrd_memory_mode = memory_mode;
204
+ host->update_every = update_every;
205
+ host->storage_engine_id = storage_engine_id;
206
207
rrdhost_init_os(host, os);
208
rrdhost_init_timezone(host, tzone, abbrev_tzone, utc_offset);
246
rrdhost_option_clear(host, RRDHOST_OPTION_SENDER_ENABLED);
247
}
248
280
-static RRDHOST *rrdhost_create(
249
+RRDHOST *rrdhost_create(
250
const char *hostname,
251
const char *registry_hostname,
252
const char *guid,
259
const char *program_version,
260
int update_every,
261
long entries,
293
- RRD_MEMORY_MODE memory_mode,
262
+ STORAGE_ENGINE_ID storage_engine_id,
263
unsigned int health_enabled,
264
unsigned int rrdpush_enabled,
265
char *rrdpush_destination,
274
) {
275
netdata_log_debug(D_RRDHOST, "Host '%s': adding with guid '%s'", hostname, guid);
276
308
- if(memory_mode == RRD_MEMORY_MODE_DBENGINE && !dbengine_enabled) {
309
- netdata_log_error("memory mode 'dbengine' is not enabled, but host '%s' is configured for it. Falling back to 'alloc'",
310
- hostname);
311
- memory_mode = RRD_MEMORY_MODE_ALLOC;
277
+ if(storage_engine_id == STORAGE_ENGINE_DBENGINE && !rrdb.dbengine_enabled) {
278
+ netdata_log_error("memory mode 'dbengine' is not enabled, but host '%s' is configured for it. Falling back to 'alloc'", hostname);
279
+ storage_engine_id = STORAGE_ENGINE_ALLOC;
280
}
281
282
#ifdef ENABLE_DBENGINE
315
- int is_legacy = (memory_mode == RRD_MEMORY_MODE_DBENGINE) && is_legacy_child(guid);
283
+ int is_legacy = (storage_engine_id == STORAGE_ENGINE_DBENGINE) && is_legacy_child(guid);
284
#else
285
int is_legacy = 1;
286
#endif
287
320
- int is_in_multihost = (memory_mode == RRD_MEMORY_MODE_DBENGINE && !is_legacy);
288
+ int is_in_multihost = (storage_engine_id == STORAGE_ENGINE_DBENGINE && !is_legacy);
289
RRDHOST *host = callocz(1, sizeof(RRDHOST));
290
__atomic_add_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(RRDHOST), __ATOMIC_RELAXED);
291
292
strncpyz(host->machine_guid, guid, GUID_LEN + 1);
293
326
- set_host_properties(host, (update_every > 0)?update_every:1, memory_mode, registry_hostname, os,
294
+ set_host_properties(host, (update_every > 0)?update_every:1, storage_engine_id, registry_hostname, os,
295
tags, timezone, abbrev_timezone, utc_offset, program_name, program_version);
296
297
rrdhost_init_hostname(host, hostname, false);
298
331
- host->rrd_history_entries = align_entries_to_pagesize(memory_mode, entries);
332
- host->health.health_enabled = ((memory_mode == RRD_MEMORY_MODE_NONE)) ? 0 : health_enabled;
299
+ host->rrd_history_entries = align_entries_to_pagesize(storage_engine_id, entries);
300
+ host->health.health_enabled = ((storage_engine_id == STORAGE_ENGINE_NONE)) ? 0 : health_enabled;
301
302
if (likely(!archived)) {
303
rrdfunctions_init(host);
315
host->rrdpush_replication_step = rrdpush_replication_step;
316
host->rrdpush_receiver_replication_percent = 100.0;
317
350
- switch(memory_mode) {
351
- default:
352
- case RRD_MEMORY_MODE_ALLOC:
353
- case RRD_MEMORY_MODE_MAP:
354
- case RRD_MEMORY_MODE_SAVE:
355
- case RRD_MEMORY_MODE_RAM:
356
- if(host->rrdpush_seconds_to_replicate > (time_t) host->rrd_history_entries * (time_t) host->rrd_update_every)
357
- host->rrdpush_seconds_to_replicate = (time_t) host->rrd_history_entries * (time_t) host->rrd_update_every;
318
+ switch(storage_engine_id) {
319
+ case STORAGE_ENGINE_DBENGINE:
320
break;
359
-
360
- case RRD_MEMORY_MODE_DBENGINE:
321
+ case STORAGE_ENGINE_ALLOC:
322
+ case STORAGE_ENGINE_MAP:
323
+ case STORAGE_ENGINE_SAVE:
324
+ case STORAGE_ENGINE_RAM:
325
+ default:
326
+ if(host->rrdpush_seconds_to_replicate > (time_t) host->rrd_history_entries * (time_t) host->update_every)
327
+ host->rrdpush_seconds_to_replicate = (time_t) host->rrd_history_entries * (time_t) host->update_every;
328
break;
329
}
330
354
host->cache_dir = strdupz(filename);
355
}
356
390
- if((host->rrd_memory_mode == RRD_MEMORY_MODE_MAP || host->rrd_memory_mode == RRD_MEMORY_MODE_SAVE ||
391
- (host->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE && is_legacy))) {
357
+ if((host->storage_engine_id == STORAGE_ENGINE_MAP || host->storage_engine_id == STORAGE_ENGINE_SAVE ||
358
+ (host->storage_engine_id == STORAGE_ENGINE_DBENGINE && is_legacy))) {
359
int r = mkdir(host->cache_dir, 0775);
360
if(r != 0 && errno != EEXIST)
361
netdata_log_error("Host '%s': cannot create directory '%s'", rrdhost_hostname(host), host->cache_dir);
375
rrdcalctemplate_index_init(host);
376
rrdcalc_rrdhost_index_init(host);
377
411
- if (host->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
378
+ if (host->storage_engine_id == STORAGE_ENGINE_DBENGINE) {
379
#ifdef ENABLE_DBENGINE
380
char dbenginepath[FILENAME_MAX + 1];
381
int ret;
391
if (is_legacy) {
392
// initialize legacy dbengine instance as needed
393
427
- host->db[0].mode = RRD_MEMORY_MODE_DBENGINE;
428
- host->db[0].eng = storage_engine_get(host->db[0].mode);
394
+ host->db[0].id = STORAGE_ENGINE_DBENGINE;
395
host->db[0].tier_grouping = get_tier_grouping(0);
396
431
- ret = rrdeng_init(
432
- (struct rrdengine_instance **)&host->db[0].instance,
433
- dbenginepath,
434
- default_rrdeng_disk_quota_mb,
435
- 0); // may fail here for legacy dbengine initialization
397
+ // may fail here for legacy dbengine initialization
398
+ ret = rrdeng_init(&host->db[0].instance, dbenginepath, rrdb.default_rrdeng_disk_quota_mb, 0);
399
400
if(ret == 0) {
438
- rrdeng_readiness_wait((struct rrdengine_instance *)host->db[0].instance);
401
+ rrdeng_readiness_wait(host->db[0].instance);
402
403
// assign the rest of the shared storage instances to it
404
// to allow them collect its metrics too
405
443
- for(size_t tier = 1; tier < storage_tiers ; tier++) {
444
- host->db[tier].mode = RRD_MEMORY_MODE_DBENGINE;
445
- host->db[tier].eng = storage_engine_get(host->db[tier].mode);
446
- host->db[tier].instance = (STORAGE_INSTANCE *) multidb_ctx[tier];
406
+ for(size_t tier = 1; tier < rrdb.storage_tiers ; tier++) {
407
+ host->db[tier].id= STORAGE_ENGINE_DBENGINE;
408
+ host->db[tier].instance = rrdb.multidb_ctx[tier];
409
host->db[tier].tier_grouping = get_tier_grouping(tier);
410
}
411
}
412
}
413
else {
452
- for(size_t tier = 0; tier < storage_tiers ; tier++) {
453
- host->db[tier].mode = RRD_MEMORY_MODE_DBENGINE;
454
- host->db[tier].eng = storage_engine_get(host->db[tier].mode);
455
- host->db[tier].instance = (STORAGE_INSTANCE *)multidb_ctx[tier];
414
+ for(size_t tier = 0; tier < rrdb.storage_tiers ; tier++) {
415
+ host->db[tier].id = STORAGE_ENGINE_DBENGINE;
416
+ host->db[tier].instance = rrdb.multidb_ctx[tier];
417
host->db[tier].tier_grouping = get_tier_grouping(tier);
418
}
419
}
430
}
431
432
#else
472
- fatal("RRD_MEMORY_MODE_DBENGINE is not supported in this platform.");
433
+ fatal("STORAGE_ENGINE_DBENGINE is not supported in this platform.");
434
#endif
435
}
436
else {
476
- host->db[0].mode = host->rrd_memory_mode;
477
- host->db[0].eng = storage_engine_get(host->db[0].mode);
437
+ host->db[0].id = host->storage_engine_id;
438
host->db[0].instance = NULL;
439
host->db[0].tier_grouping = get_tier_grouping(0);
440
441
#ifdef ENABLE_DBENGINE
442
// the first tier is reserved for the non-dbengine modes
483
- for(size_t tier = 1; tier < storage_tiers ; tier++) {
484
- host->db[tier].mode = RRD_MEMORY_MODE_DBENGINE;
485
- host->db[tier].eng = storage_engine_get(host->db[tier].mode);
486
- host->db[tier].instance = (STORAGE_INSTANCE *) multidb_ctx[tier];
443
+ for(size_t tier = 1; tier < rrdb.storage_tiers ; tier++) {
444
+ host->db[tier].id = STORAGE_ENGINE_DBENGINE;
445
+ host->db[tier].instance = rrdb.multidb_ctx[tier];
446
host->db[tier].tier_grouping = get_tier_grouping(tier);
447
}
448
#endif
476
rrdhost_index_add_hostname(host);
477
478
if(is_localhost)
520
- DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(localhost, host, prev, next);
479
+ DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(rrdb.localhost, host, prev, next);
480
else
522
- DOUBLE_LINKED_LIST_APPEND_ITEM_UNSAFE(localhost, host, prev, next);
481
+ DOUBLE_LINKED_LIST_APPEND_ITEM_UNSAFE(rrdb.localhost, host, prev, next);
482
483
rrd_unlock();
484
507
, rrdhost_tags(host)
508
, rrdhost_program_name(host)
509
, rrdhost_program_version(host)
551
- , host->rrd_update_every
552
- , rrd_memory_mode_name(host->rrd_memory_mode)
510
+ , host->update_every
511
+ , storage_engine_name(host->storage_engine_id)
512
, host->rrd_history_entries
513
, rrdhost_has_rrdpush_sender_enabled(host)?"enabled":"disabled"
514
, host->rrdpush_send_destination?host->rrdpush_send_destination:""
543
, const char *program_version
544
, int update_every
545
, long history
587
- , RRD_MEMORY_MODE mode
546
+ , STORAGE_ENGINE_ID storage_engine_id
547
, unsigned int health_enabled
548
, unsigned int rrdpush_enabled
549
, char *rrdpush_destination
559
560
spinlock_lock(&host->rrdhost_update_lock);
561
603
- host->health.health_enabled = (mode == RRD_MEMORY_MODE_NONE) ? 0 : health_enabled;
562
+ host->health.health_enabled = (storage_engine_id == STORAGE_ENGINE_NONE) ? 0 : health_enabled;
563
564
{
565
struct rrdhost_system_info *old = host->system_info;
595
string_freez(t);
596
}
597
639
- if(host->rrd_update_every != update_every)
598
+ if(host->update_every != update_every)
599
netdata_log_error("Host '%s' has an update frequency of %d seconds, but the wanted one is %d seconds. "
600
"Restart netdata here to apply the new settings.",
642
- rrdhost_hostname(host), host->rrd_update_every, update_every);
601
+ rrdhost_hostname(host), host->update_every, update_every);
602
644
- if(host->rrd_memory_mode != mode)
603
+ if(host->storage_engine_id != storage_engine_id) {
604
netdata_log_error("Host '%s' has memory mode '%s', but the wanted one is '%s'. "
605
"Restart netdata here to apply the new settings.",
647
- rrdhost_hostname(host),
648
- rrd_memory_mode_name(host->rrd_memory_mode),
649
- rrd_memory_mode_name(mode));
650
-
651
- else if(host->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE && host->rrd_history_entries < history)
606
+ rrdhost_hostname(host), storage_engine_name(host->storage_engine_id), storage_engine_name(storage_engine_id));
607
+ } else if(host->storage_engine_id != STORAGE_ENGINE_DBENGINE && host->rrd_history_entries < history) {
608
netdata_log_error("Host '%s' has history of %d entries, but the wanted one is %ld entries. "
609
"Restart netdata here to apply the new settings.",
654
- rrdhost_hostname(host),
655
- host->rrd_history_entries,
656
- history);
610
+ rrdhost_hostname(host), host->rrd_history_entries, history);
611
+ }
612
613
// update host tags
614
rrdhost_init_tags(host, tags);
654
spinlock_unlock(&host->rrdhost_update_lock);
655
}
656
702
-RRDHOST *rrdhost_find_or_create(
657
+RRDHOST *rrdhost_get_or_create(
658
const char *hostname
659
, const char *registry_hostname
660
, const char *guid
667
, const char *program_version
668
, int update_every
669
, long history
715
- , RRD_MEMORY_MODE mode
670
+ , STORAGE_ENGINE_ID storage_engine_id
671
, unsigned int health_enabled
672
, unsigned int rrdpush_enabled
673
, char *rrdpush_destination
682
netdata_log_debug(D_RRDHOST, "Searching for host '%s' with guid '%s'", hostname, guid);
683
684
RRDHOST *host = rrdhost_find_by_guid(guid);
730
- if (unlikely(host && host->rrd_memory_mode != mode && rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED))) {
685
+ if (unlikely(host && host->storage_engine_id != storage_engine_id && rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED))) {
686
687
if (likely(!archived && rrdhost_flag_check(host, RRDHOST_FLAG_PENDING_CONTEXT_LOAD)))
688
return host;
689
735
- /* If a legacy memory mode instantiates all dbengine state must be discarded to avoid inconsistencies */
690
+ /* If a legacy storage engine instantiates all dbengine state must be discarded to avoid inconsistencies */
691
netdata_log_error("Archived host '%s' has memory mode '%s', but the wanted one is '%s'. Discarding archived state.",
692
rrdhost_hostname(host),
738
- rrd_memory_mode_name(host->rrd_memory_mode),
739
- rrd_memory_mode_name(mode));
693
+ storage_engine_name(host->storage_engine_id),
694
+ storage_engine_name(storage_engine_id));
695
696
rrd_wrlock();
697
rrdhost_free___while_having_rrd_wrlock(host, true);
713
, program_version
714
, update_every
715
, history
761
- , mode
716
+ , storage_engine_id
717
, health_enabled
718
, rrdpush_enabled
719
, rrdpush_destination
742
, program_version
743
, update_every
744
, history
790
- , mode
745
+ , storage_engine_id
746
, health_enabled
747
, rrdpush_enabled
748
, rrdpush_destination
759
760
inline int rrdhost_should_be_removed(RRDHOST *host, RRDHOST *protected_host, time_t now_s) {
761
if(host != protected_host
807
- && host != localhost
762
+ && host != rrdb.localhost
763
&& rrdhost_receiver_replicating_charts(host) == 0
764
&& rrdhost_sender_replicating_charts(host) == 0
765
&& rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN)
766
&& !rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED)
767
&& !host->receiver
768
&& host->child_disconnected_time
814
- && host->child_disconnected_time + rrdhost_free_orphan_time_s < now_s)
769
+ && host->child_disconnected_time + rrdb.rrdhost_free_orphan_time_s < now_s)
770
return 1;
771
772
return 0;
773
}
774
820
-// ----------------------------------------------------------------------------
821
-// RRDHOST global / startup initialization
822
-
823
-#ifdef ENABLE_DBENGINE
824
-struct dbengine_initialization {
825
- netdata_thread_t thread;
826
- char path[FILENAME_MAX + 1];
827
- int disk_space_mb;
828
- size_t tier;
829
- int ret;
830
-};
831
-
832
-void *dbengine_tier_init(void *ptr) {
833
- struct dbengine_initialization *dbi = ptr;
834
- dbi->ret = rrdeng_init(NULL, dbi->path, dbi->disk_space_mb, dbi->tier);
835
- return ptr;
836
-}
837
-#endif
838
-
839
-void dbengine_init(char *hostname) {
840
-#ifdef ENABLE_DBENGINE
841
- use_direct_io = config_get_boolean(CONFIG_SECTION_DB, "dbengine use direct io", use_direct_io);
842
-
843
- unsigned read_num = (unsigned)config_get_number(CONFIG_SECTION_DB, "dbengine pages per extent", MAX_PAGES_PER_EXTENT);
844
- if (read_num > 0 && read_num <= MAX_PAGES_PER_EXTENT)
845
- rrdeng_pages_per_extent = read_num;
846
- else {
847
- netdata_log_error("Invalid dbengine pages per extent %u given. Using %u.", read_num, rrdeng_pages_per_extent);
848
- config_set_number(CONFIG_SECTION_DB, "dbengine pages per extent", rrdeng_pages_per_extent);
849
- }
850
-
851
- storage_tiers = config_get_number(CONFIG_SECTION_DB, "storage tiers", storage_tiers);
852
- if(storage_tiers < 1) {
853
- netdata_log_error("At least 1 storage tier is required. Assuming 1.");
854
- storage_tiers = 1;
855
- config_set_number(CONFIG_SECTION_DB, "storage tiers", storage_tiers);
856
- }
857
- if(storage_tiers > RRD_STORAGE_TIERS) {
858
- netdata_log_error("Up to %d storage tier are supported. Assuming %d.", RRD_STORAGE_TIERS, RRD_STORAGE_TIERS);
859
- storage_tiers = RRD_STORAGE_TIERS;
860
- config_set_number(CONFIG_SECTION_DB, "storage tiers", storage_tiers);
861
- }
862
-
863
- bool parallel_initialization = (storage_tiers <= (size_t)get_netdata_cpus()) ? true : false;
864
- parallel_initialization = config_get_boolean(CONFIG_SECTION_DB, "dbengine parallel initialization", parallel_initialization);
865
-
866
- struct dbengine_initialization tiers_init[RRD_STORAGE_TIERS] = {};
867
-
868
- size_t created_tiers = 0;
869
- char dbenginepath[FILENAME_MAX + 1];
870
- char dbengineconfig[200 + 1];
871
- int divisor = 1;
872
- for(size_t tier = 0; tier < storage_tiers ;tier++) {
873
- if(tier == 0)
874
- snprintfz(dbenginepath, FILENAME_MAX, "%s/dbengine", netdata_configured_cache_dir);
875
- else
876
- snprintfz(dbenginepath, FILENAME_MAX, "%s/dbengine-tier%zu", netdata_configured_cache_dir, tier);
877
-
878
- int ret = mkdir(dbenginepath, 0775);
879
- if (ret != 0 && errno != EEXIST) {
880
- netdata_log_error("DBENGINE on '%s': cannot create directory '%s'", hostname, dbenginepath);
881
- break;
882
- }
883
-
884
- if(tier > 0)
885
- divisor *= 2;
886
-
887
- int disk_space_mb = default_multidb_disk_quota_mb / divisor;
888
- size_t grouping_iterations = storage_tiers_grouping_iterations[tier];
889
- RRD_BACKFILL backfill = storage_tiers_backfill[tier];
890
-
891
- if(tier > 0) {
892
- snprintfz(dbengineconfig, 200, "dbengine tier %zu multihost disk space MB", tier);
893
- disk_space_mb = config_get_number(CONFIG_SECTION_DB, dbengineconfig, disk_space_mb);
894
-
895
- snprintfz(dbengineconfig, 200, "dbengine tier %zu update every iterations", tier);
896
- grouping_iterations = config_get_number(CONFIG_SECTION_DB, dbengineconfig, grouping_iterations);
897
- if(grouping_iterations < 2) {
898
- grouping_iterations = 2;
899
- config_set_number(CONFIG_SECTION_DB, dbengineconfig, grouping_iterations);
900
- netdata_log_error("DBENGINE on '%s': 'dbegnine tier %zu update every iterations' cannot be less than 2. Assuming 2.",
901
- hostname,
902
- tier);
903
- }
904
-
905
- snprintfz(dbengineconfig, 200, "dbengine tier %zu backfill", tier);
906
- const char *bf = config_get(CONFIG_SECTION_DB, dbengineconfig, backfill == RRD_BACKFILL_NEW ? "new" : backfill == RRD_BACKFILL_FULL ? "full" : "none");
907
- if(strcmp(bf, "new") == 0) backfill = RRD_BACKFILL_NEW;
908
- else if(strcmp(bf, "full") == 0) backfill = RRD_BACKFILL_FULL;
909
- else if(strcmp(bf, "none") == 0) backfill = RRD_BACKFILL_NONE;
910
- else {
911
- netdata_log_error("DBENGINE: unknown backfill value '%s', assuming 'new'", bf);
912
- config_set(CONFIG_SECTION_DB, dbengineconfig, "new");
913
- backfill = RRD_BACKFILL_NEW;
914
- }
915
- }
916
-
917
- storage_tiers_grouping_iterations[tier] = grouping_iterations;
918
- storage_tiers_backfill[tier] = backfill;
919
-
920
- if(tier > 0 && get_tier_grouping(tier) > 65535) {
921
- storage_tiers_grouping_iterations[tier] = 1;
922
- netdata_log_error("DBENGINE on '%s': dbengine tier %zu gives aggregation of more than 65535 points of tier 0. Disabling tiers above %zu",
923
- hostname,
924
- tier,
925
- tier);
926
- break;
927
- }
928
-
929
- internal_error(true, "DBENGINE tier %zu grouping iterations is set to %zu", tier, storage_tiers_grouping_iterations[tier]);
930
-
931
- tiers_init[tier].disk_space_mb = disk_space_mb;
932
- tiers_init[tier].tier = tier;
933
- strncpyz(tiers_init[tier].path, dbenginepath, FILENAME_MAX);
934
- tiers_init[tier].ret = 0;
935
-
936
- if(parallel_initialization) {
937
- char tag[NETDATA_THREAD_TAG_MAX + 1];
938
- snprintfz(tag, NETDATA_THREAD_TAG_MAX, "DBENGINIT[%zu]", tier);
939
- netdata_thread_create(&tiers_init[tier].thread, tag, NETDATA_THREAD_OPTION_JOINABLE,
940
- dbengine_tier_init, &tiers_init[tier]);
941
- }
942
- else
943
- dbengine_tier_init(&tiers_init[tier]);
944
- }
945
-
946
- for(size_t tier = 0; tier < storage_tiers ;tier++) {
947
- void *ptr;
948
-
949
- if(parallel_initialization)
950
- netdata_thread_join(tiers_init[tier].thread, &ptr);
951
-
952
- if(tiers_init[tier].ret != 0) {
953
- netdata_log_error("DBENGINE on '%s': Failed to initialize multi-host database tier %zu on path '%s'",
954
- hostname,
955
- tiers_init[tier].tier,
956
- tiers_init[tier].path);
957
- }
958
- else if(created_tiers == tier)
959
- created_tiers++;
960
- }
961
-
962
- if(created_tiers && created_tiers < storage_tiers) {
963
- netdata_log_error("DBENGINE on '%s': Managed to create %zu tiers instead of %zu. Continuing with %zu available.",
964
- hostname,
965
- created_tiers,
966
- storage_tiers,
967
- created_tiers);
968
- storage_tiers = created_tiers;
969
- }
970
- else if(!created_tiers)
971
- fatal("DBENGINE on '%s', failed to initialize databases at '%s'.", hostname, netdata_configured_cache_dir);
972
-
973
- for(size_t tier = 0; tier < storage_tiers ;tier++)
974
- rrdeng_readiness_wait(multidb_ctx[tier]);
975
-
976
- dbengine_enabled = true;
977
-#else
978
- storage_tiers = config_get_number(CONFIG_SECTION_DB, "storage tiers", 1);
979
- if(storage_tiers != 1) {
980
- netdata_log_error("DBENGINE is not available on '%s', so only 1 database tier can be supported.", hostname);
981
- storage_tiers = 1;
982
- config_set_number(CONFIG_SECTION_DB, "storage tiers", storage_tiers);
983
- }
984
- dbengine_enabled = false;
985
-#endif
986
-}
987
-
988
-int rrd_init(char *hostname, struct rrdhost_system_info *system_info, bool unittest) {
989
- rrdhost_init();
990
-
991
- if (unlikely(sql_init_database(DB_CHECK_NONE, system_info ? 0 : 1))) {
992
- if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
993
- set_late_global_environment(system_info);
994
- fatal("Failed to initialize SQLite");
995
- }
996
- netdata_log_info("Skipping SQLITE metadata initialization since memory mode is not dbengine");
997
- }
998
-
999
- if (unlikely(sql_init_context_database(system_info ? 0 : 1))) {
1000
- error_report("Failed to initialize context metadata database");
1001
- }
1002
-
1003
- if (unlikely(unittest)) {
1004
- dbengine_enabled = true;
1005
- }
1006
- else {
1007
- health_init();
1008
- rrdpush_init();
1009
-
1010
- if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE || rrdpush_receiver_needs_dbengine()) {
1011
- netdata_log_info("DBENGINE: Initializing ...");
1012
- dbengine_init(hostname);
1013
- }
1014
- else {
1015
- netdata_log_info("DBENGINE: Not initializing ...");
1016
- storage_tiers = 1;
1017
- }
1018
-
1019
- if (!dbengine_enabled) {
1020
- if (storage_tiers > 1) {
1021
- netdata_log_error("dbengine is not enabled, but %zu tiers have been requested. Resetting tiers to 1",
1022
- storage_tiers);
1023
- storage_tiers = 1;
1024
- }
1025
-
1026
- if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
1027
- netdata_log_error("dbengine is not enabled, but it has been given as the default db mode. Resetting db mode to alloc");
1028
- default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC;
1029
- }
1030
- }
1031
- }
1032
-
1033
- if(!unittest)
1034
- metadata_sync_init();
1035
-
1036
- netdata_log_debug(D_RRDHOST, "Initializing localhost with hostname '%s'", hostname);
1037
- localhost = rrdhost_create(
1038
- hostname
1039
- , registry_get_this_machine_hostname()
1040
- , registry_get_this_machine_guid()
1041
- , os_type
1042
- , netdata_configured_timezone
1043
- , netdata_configured_abbrev_timezone
1044
- , netdata_configured_utc_offset
1045
- , ""
1046
- , program_name
1047
- , program_version
1048
- , default_rrd_update_every
1049
- , default_rrd_history_entries
1050
- , default_rrd_memory_mode
1051
- , default_health_enabled
1052
- , default_rrdpush_enabled
1053
- , default_rrdpush_destination
1054
- , default_rrdpush_api_key
1055
- , default_rrdpush_send_charts_matching
1056
- , default_rrdpush_enable_replication
1057
- , default_rrdpush_seconds_to_replicate
1058
- , default_rrdpush_replication_step
1059
- , system_info
1060
- , 1
1061
- , 0
1062
- );
1063
-
1064
- if (unlikely(!localhost)) {
1065
- return 1;
1066
- }
1067
-
1068
-#ifdef NETDATA_DEV_MODE
1069
- // we register this only on localhost
1070
- // for the other nodes, the origin server should register it
1071
- rrd_collector_started(); // this creates a collector that runs for as long as netdata runs
1072
- rrd_collector_add_function(localhost, NULL, "streaming", 10,
1073
- RRDFUNCTIONS_STREAMING_HELP, true,
1074
- rrdhost_function_streaming, NULL);
1075
-#endif
1076
-
1077
- if (likely(system_info)) {
1078
- migrate_localhost(&localhost->host_uuid);
1079
- sql_aclk_sync_init();
1080
- web_client_api_v1_management_init();
1081
- }
1082
- return localhost==NULL;
1083
-}
1084
-
775
// ----------------------------------------------------------------------------
776
// RRDHOST - free
777
874
rrdhost_index_del_by_guid(host);
875
876
if (host->prev)
1187
- DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(localhost, host, prev, next);
877
+ DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(rrdb.localhost, host, prev, next);
878
}
879
880
// ------------------------------------------------------------------------
895
// release its children resources
896
897
#ifdef ENABLE_DBENGINE
1208
- for(size_t tier = 0; tier < storage_tiers ;tier++) {
1209
- if(host->db[tier].mode == RRD_MEMORY_MODE_DBENGINE
898
+ for(size_t tier = 0; tier < rrdb.storage_tiers ;tier++) {
899
+ if(host->db[tier].id == STORAGE_ENGINE_DBENGINE
900
&& host->db[tier].instance
901
&& !is_storage_engine_shared(host->db[tier].instance))
1212
- rrdeng_prepare_exit((struct rrdengine_instance *)host->db[tier].instance);
902
+ rrdeng_prepare_exit(host->db[tier].instance);
903
}
904
#endif
905
916
health_alarm_log_free(host);
917
918
#ifdef ENABLE_DBENGINE
1229
- for(size_t tier = 0; tier < storage_tiers ;tier++) {
1230
- if(host->db[tier].mode == RRD_MEMORY_MODE_DBENGINE
919
+ for(size_t tier = 0; tier < rrdb.storage_tiers ;tier++) {
920
+ if(host->db[tier].id == STORAGE_ENGINE_DBENGINE
921
&& host->db[tier].instance
922
&& !is_storage_engine_shared(host->db[tier].instance))
1233
- rrdeng_exit((struct rrdengine_instance *)host->db[tier].instance);
923
+ rrdeng_exit(host->db[tier].instance);
924
}
925
#endif
926
957
rrdfamily_index_destroy(host);
958
rrdfunctions_destroy(host);
959
rrdvariables_destroy(host->rrdvars);
1270
- if (host == localhost)
960
+ if (host == rrdb.localhost)
961
rrdvariables_destroy(health_rrdvars);
962
963
rrdhost_destroy_rrdcontexts(host);
971
rrd_wrlock();
972
973
/* Make sure child-hosts are released before the localhost. */
1284
- while(localhost && localhost->next)
1285
- rrdhost_free___while_having_rrd_wrlock(localhost->next, true);
974
+ while (rrdb.localhost && rrdb.localhost->next)
975
+ rrdhost_free___while_having_rrd_wrlock(rrdb.localhost->next, true);
976
1287
- if(localhost)
1288
- rrdhost_free___while_having_rrd_wrlock(localhost, true);
977
+ if (rrdb.localhost)
978
+ rrdhost_free___while_having_rrd_wrlock(rrdb.localhost, true);
979
980
rrd_unlock();
981
}
982
983
void rrd_finalize_collection_for_all_hosts(void) {
984
RRDHOST *host;
1295
- dfe_start_reentrant(rrdhost_root_index, host) {
985
+ dfe_start_reentrant(rrdb.rrdhost_root_index, host) {
986
rrdhost_finalize_collection(host);
987
}
988
dfe_done(host);
1006
rrdset_foreach_done(st);
1007
}
1008
1319
-struct rrdhost_system_info *rrdhost_labels_to_system_info(DICTIONARY *labels) {
1320
- struct rrdhost_system_info *info = callocz(1, sizeof(struct rrdhost_system_info));
1321
- info->hops = 1;
1322
-
1323
- rrdlabels_get_value_strdup_or_null(labels, &info->cloud_provider_type, "_cloud_provider_type");
1324
- rrdlabels_get_value_strdup_or_null(labels, &info->cloud_instance_type, "_cloud_instance_type");
1325
- rrdlabels_get_value_strdup_or_null(labels, &info->cloud_instance_region, "_cloud_instance_region");
1326
- rrdlabels_get_value_strdup_or_null(labels, &info->host_os_name, "_os_name");
1327
- rrdlabels_get_value_strdup_or_null(labels, &info->host_os_version, "_os_version");
1328
- rrdlabels_get_value_strdup_or_null(labels, &info->kernel_version, "_kernel_version");
1329
- rrdlabels_get_value_strdup_or_null(labels, &info->host_cores, "_system_cores");
1330
- rrdlabels_get_value_strdup_or_null(labels, &info->host_cpu_freq, "_system_cpu_freq");
1331
- rrdlabels_get_value_strdup_or_null(labels, &info->host_ram_total, "_system_ram_total");
1332
- rrdlabels_get_value_strdup_or_null(labels, &info->host_disk_space, "_system_disk_space");
1333
- rrdlabels_get_value_strdup_or_null(labels, &info->architecture, "_architecture");
1334
- rrdlabels_get_value_strdup_or_null(labels, &info->virtualization, "_virtualization");
1335
- rrdlabels_get_value_strdup_or_null(labels, &info->container, "_container");
1336
- rrdlabels_get_value_strdup_or_null(labels, &info->container_detection, "_container_detection");
1337
- rrdlabels_get_value_strdup_or_null(labels, &info->virt_detection, "_virt_detection");
1338
- rrdlabels_get_value_strdup_or_null(labels, &info->is_k8s_node, "_is_k8s_node");
1339
- rrdlabels_get_value_strdup_or_null(labels, &info->install_type, "_install_type");
1340
- rrdlabels_get_value_strdup_or_null(labels, &info->prebuilt_arch, "_prebuilt_arch");
1341
- rrdlabels_get_value_strdup_or_null(labels, &info->prebuilt_dist, "_prebuilt_dist");
1342
-
1343
- return info;
1344
-}
1345
-
1346
-static void rrdhost_load_auto_labels(void) {
1347
- DICTIONARY *labels = localhost->rrdlabels;
1348
-
1349
- if (localhost->system_info->cloud_provider_type)
1350
- rrdlabels_add(labels, "_cloud_provider_type", localhost->system_info->cloud_provider_type, RRDLABEL_SRC_AUTO);
1351
-
1352
- if (localhost->system_info->cloud_instance_type)
1353
- rrdlabels_add(labels, "_cloud_instance_type", localhost->system_info->cloud_instance_type, RRDLABEL_SRC_AUTO);
1354
-
1355
- if (localhost->system_info->cloud_instance_region)
1356
- rrdlabels_add(labels, "_cloud_instance_region", localhost->system_info->cloud_instance_region, RRDLABEL_SRC_AUTO);
1357
-
1358
- if (localhost->system_info->host_os_name)
1359
- rrdlabels_add(labels, "_os_name", localhost->system_info->host_os_name, RRDLABEL_SRC_AUTO);
1360
-
1361
- if (localhost->system_info->host_os_version)
1362
- rrdlabels_add(labels, "_os_version", localhost->system_info->host_os_version, RRDLABEL_SRC_AUTO);
1363
-
1364
- if (localhost->system_info->kernel_version)
1365
- rrdlabels_add(labels, "_kernel_version", localhost->system_info->kernel_version, RRDLABEL_SRC_AUTO);
1366
-
1367
- if (localhost->system_info->host_cores)
1368
- rrdlabels_add(labels, "_system_cores", localhost->system_info->host_cores, RRDLABEL_SRC_AUTO);
1369
-
1370
- if (localhost->system_info->host_cpu_freq)
1371
- rrdlabels_add(labels, "_system_cpu_freq", localhost->system_info->host_cpu_freq, RRDLABEL_SRC_AUTO);
1372
-
1373
- if (localhost->system_info->host_ram_total)
1374
- rrdlabels_add(labels, "_system_ram_total", localhost->system_info->host_ram_total, RRDLABEL_SRC_AUTO);
1375
-
1376
- if (localhost->system_info->host_disk_space)
1377
- rrdlabels_add(labels, "_system_disk_space", localhost->system_info->host_disk_space, RRDLABEL_SRC_AUTO);
1378
-
1379
- if (localhost->system_info->architecture)
1380
- rrdlabels_add(labels, "_architecture", localhost->system_info->architecture, RRDLABEL_SRC_AUTO);
1381
-
1382
- if (localhost->system_info->virtualization)
1383
- rrdlabels_add(labels, "_virtualization", localhost->system_info->virtualization, RRDLABEL_SRC_AUTO);
1384
-
1385
- if (localhost->system_info->container)
1386
- rrdlabels_add(labels, "_container", localhost->system_info->container, RRDLABEL_SRC_AUTO);
1387
-
1388
- if (localhost->system_info->container_detection)
1389
- rrdlabels_add(labels, "_container_detection", localhost->system_info->container_detection, RRDLABEL_SRC_AUTO);
1390
-
1391
- if (localhost->system_info->virt_detection)
1392
- rrdlabels_add(labels, "_virt_detection", localhost->system_info->virt_detection, RRDLABEL_SRC_AUTO);
1393
-
1394
- if (localhost->system_info->is_k8s_node)
1395
- rrdlabels_add(labels, "_is_k8s_node", localhost->system_info->is_k8s_node, RRDLABEL_SRC_AUTO);
1396
-
1397
- if (localhost->system_info->install_type)
1398
- rrdlabels_add(labels, "_install_type", localhost->system_info->install_type, RRDLABEL_SRC_AUTO);
1399
-
1400
- if (localhost->system_info->prebuilt_arch)
1401
- rrdlabels_add(labels, "_prebuilt_arch", localhost->system_info->prebuilt_arch, RRDLABEL_SRC_AUTO);
1402
-
1403
- if (localhost->system_info->prebuilt_dist)
1404
- rrdlabels_add(labels, "_prebuilt_dist", localhost->system_info->prebuilt_dist, RRDLABEL_SRC_AUTO);
1405
-
1406
- add_aclk_host_labels();
1407
-
1408
- health_add_host_labels();
1409
-
1410
- rrdlabels_add(labels, "_is_parent", (localhost->connected_children_count > 0) ? "true" : "false", RRDLABEL_SRC_AUTO);
1411
-
1412
- if (localhost->rrdpush_send_destination)
1413
- rrdlabels_add(labels, "_streams_to", localhost->rrdpush_send_destination, RRDLABEL_SRC_AUTO);
1414
-}
1415
-
1009
void rrdhost_set_is_parent_label(void) {
1417
- int count = __atomic_load_n(&localhost->connected_children_count, __ATOMIC_RELAXED);
1010
+ int count = __atomic_load_n(&rrdb.localhost->connected_children_count, __ATOMIC_RELAXED);
1011
1012
if (count == 0 || count == 1) {
1420
- DICTIONARY *labels = localhost->rrdlabels;
1013
+ DICTIONARY *labels = rrdb.localhost->rrdlabels;
1014
rrdlabels_add(labels, "_is_parent", (count) ? "true" : "false", RRDLABEL_SRC_AUTO);
1015
1016
//queue a node info
1017
#ifdef ENABLE_ACLK
1018
if (netdata_cloud_enabled) {
1426
- aclk_queue_node_info(localhost, false);
1019
+ aclk_queue_node_info(rrdb.localhost, false);
1020
}
1021
#endif
1022
}
1023
}
1024
1432
-static void rrdhost_load_config_labels(void) {
1433
- int status = config_load(NULL, 1, CONFIG_SECTION_HOST_LABEL);
1434
- if(!status) {
1435
- char *filename = CONFIG_DIR "/" CONFIG_FILENAME;
1436
- netdata_log_error("RRDLABEL: Cannot reload the configuration file '%s', using labels in memory", filename);
1437
- }
1438
-
1439
- struct section *co = appconfig_get_section(&netdata_config, CONFIG_SECTION_HOST_LABEL);
1440
- if(co) {
1441
- config_section_wrlock(co);
1442
- struct config_option *cv;
1443
- for(cv = co->values; cv ; cv = cv->next) {
1444
- rrdlabels_add(localhost->rrdlabels, cv->name, cv->value, RRDLABEL_SRC_CONFIG);
1445
- cv->flags |= CONFIG_VALUE_USED;
1446
- }
1447
- config_section_unlock(co);
1448
- }
1449
-}
1450
-
1451
-static void rrdhost_load_kubernetes_labels(void) {
1452
- char label_script[sizeof(char) * (strlen(netdata_configured_primary_plugins_dir) + strlen("get-kubernetes-labels.sh") + 2)];
1453
- sprintf(label_script, "%s/%s", netdata_configured_primary_plugins_dir, "get-kubernetes-labels.sh");
1454
-
1455
- if (unlikely(access(label_script, R_OK) != 0)) {
1456
- netdata_log_error("Kubernetes pod label fetching script %s not found.",label_script);
1457
- return;
1458
- }
1459
-
1460
- netdata_log_debug(D_RRDHOST, "Attempting to fetch external labels via %s", label_script);
1461
-
1462
- pid_t pid;
1463
- FILE *fp_child_input;
1464
- FILE *fp_child_output = netdata_popen(label_script, &pid, &fp_child_input);
1465
- if(!fp_child_output) return;
1466
-
1467
- char buffer[1000 + 1];
1468
- while (fgets(buffer, 1000, fp_child_output) != NULL)
1469
- rrdlabels_add_pair(localhost->rrdlabels, buffer, RRDLABEL_SRC_AUTO|RRDLABEL_SRC_K8S);
1470
-
1471
- // Non-zero exit code means that all the script output is error messages. We've shown already any message that didn't include a ':'
1472
- // Here we'll inform with an ERROR that the script failed, show whatever (if anything) was added to the list of labels, free the memory and set the return to null
1473
- int rc = netdata_pclose(fp_child_input, fp_child_output, pid);
1474
- if(rc)
1475
- netdata_log_error("%s exited abnormally. Failed to get kubernetes labels.", label_script);
1476
-}
1477
-
1478
-void reload_host_labels(void) {
1479
- if(!localhost->rrdlabels)
1480
- localhost->rrdlabels = rrdlabels_create();
1481
-
1482
- rrdlabels_unmark_all(localhost->rrdlabels);
1483
-
1484
- // priority is important here
1485
- rrdhost_load_config_labels();
1486
- rrdhost_load_kubernetes_labels();
1487
- rrdhost_load_auto_labels();
1488
-
1489
- rrdhost_flag_set(localhost,RRDHOST_FLAG_METADATA_LABELS | RRDHOST_FLAG_METADATA_UPDATE);
1490
-
1491
- rrdpush_send_host_labels(localhost);
1492
-}
1493
-
1025
void rrdhost_finalize_collection(RRDHOST *host) {
1026
netdata_log_info("RRD: 'host:%s' stopping data collection...", rrdhost_hostname(host));
1027
1041
1042
RRDSET *st;
1043
1513
- if(host->rrd_memory_mode == RRD_MEMORY_MODE_SAVE || host->rrd_memory_mode == RRD_MEMORY_MODE_MAP) {
1044
+ if(host->storage_engine_id == STORAGE_ENGINE_SAVE || host->storage_engine_id == STORAGE_ENGINE_MAP) {
1045
// we get a write lock
1046
// to ensure only one thread is saving the database
1047
rrdset_foreach_write(st, host){
1056
// ----------------------------------------------------------------------------
1057
// RRDHOST - cleanup host files
1058
1059
+static void delete_obsolete_dimensions(RRDSET *st) {
1060
+ RRDDIM *rd;
1061
+
1062
+ netdata_log_info("Deleting dimensions of chart '%s' ('%s') from disk...", rrdset_id(st), rrdset_name(st));
1063
+
1064
+ rrddim_foreach_read(rd, st) {
1065
+ if(rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) {
1066
+ const char *cache_filename = rrddim_cache_filename(rd);
1067
+ if(!cache_filename) continue;
1068
+ netdata_log_info("Deleting dimension file '%s'.", cache_filename);
1069
+ if(unlikely(unlink(cache_filename) == -1))
1070
+ netdata_log_error("Cannot delete dimension file '%s'", cache_filename);
1071
+ }
1072
+ }
1073
+ rrddim_foreach_done(rd);
1074
+}
1075
+
1076
void rrdhost_cleanup_charts(RRDHOST *host) {
1077
if(!host) return;
1078
1089
rrdset_delete_files(st);
1090
1091
else if(rrdhost_delete_obsolete_charts && rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE_DIMENSIONS))
1544
- rrdset_delete_obsolete_dimensions(st);
1092
+ delete_obsolete_dimensions(st);
1093
1094
else
1095
rrdset_save(st);
1124
1125
RRDHOST *host;
1126
rrdhost_foreach_read(host) {
1579
- if (host != localhost && rrdhost_option_check(host, RRDHOST_OPTION_DELETE_ORPHAN_HOST) && !host->receiver
1127
+ if (host != rrdb.localhost && rrdhost_option_check(host, RRDHOST_OPTION_DELETE_ORPHAN_HOST) && !host->receiver
1128
/* don't delete multi-host DB host files */
1581
- && !(host->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE && is_storage_engine_shared(host->db[0].instance))
1129
+ && !(host->storage_engine_id == STORAGE_ENGINE_DBENGINE && is_storage_engine_shared(host->db[0].instance))
1130
)
1131
rrdhost_delete_charts(host);
1132
else
1291
return completion;
1292
}
1293
1294
+static void rrdhost_retention(RRDHOST *host, time_t now, bool online, time_t *from, time_t *to)
1295
+{
1296
+ spinlock_lock(&host->retention.spinlock);
1297
+ time_t first_time_s = host->retention.first_time_s;
1298
+ time_t last_time_s = host->retention.last_time_s;
1299
+ spinlock_unlock(&host->retention.spinlock);
1300
+
1301
+ if (from)
1302
+ *from = first_time_s;
1303
+
1304
+ if (to)
1305
+ *to = online ? now : last_time_s;
1306
+}
1307
+
1308
bool rrdhost_matches_window(RRDHOST *host, time_t after, time_t before, time_t now) {
1309
time_t first_time_s, last_time_s;
1310
rrdhost_retention(host, now, rrdhost_is_online(host), &first_time_s, &last_time_s);
1337
else
1338
s->db.status = RRDHOST_DB_STATUS_QUERYABLE;
1339
1778
- s->db.mode = host->rrd_memory_mode;
1340
+ s->db.storage_engine_id = host->storage_engine_id;
1341
1342
// --- ingest ---
1343
1345
s->ingest.reason = (online) ? STREAM_HANDSHAKE_NEVER : host->rrdpush_last_receiver_exit_reason;
1346
1347
netdata_mutex_lock(&host->receiver_lock);
1786
- s->ingest.hops = (host->system_info ? host->system_info->hops : (host == localhost) ? 0 : 1);
1348
+ s->ingest.hops = (host->system_info ? host->system_info->hops : (host == rrdb.localhost) ? 0 : 1);
1349
bool has_receiver = false;
1350
if (host->receiver) {
1351
has_receiver = true;
1365
if(s->db.status == RRDHOST_DB_STATUS_INITIALIZING)
1366
s->ingest.status = RRDHOST_INGEST_STATUS_INITIALIZING;
1367
1806
- else if (host == localhost || rrdhost_option_check(host, RRDHOST_OPTION_VIRTUAL_HOST)) {
1368
+ else if (host == rrdb.localhost || rrdhost_option_check(host, RRDHOST_OPTION_VIRTUAL_HOST)) {
1369
s->ingest.status = RRDHOST_INGEST_STATUS_ONLINE;
1370
s->ingest.since = netdata_start_time;
1371
}
1386
s->ingest.status = RRDHOST_INGEST_STATUS_OFFLINE;
1387
}
1388
1827
- if(host == localhost)
1389
+ if(host == rrdb.localhost)
1390
s->ingest.type = RRDHOST_INGEST_TYPE_LOCALHOST;
1391
else if(has_receiver || rrdhost_flag_set(host, RRDHOST_FLAG_RRDPUSH_RECEIVER_DISCONNECTED))
1392
s->ingest.type = RRDHOST_INGEST_TYPE_CHILD;