diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 17:33:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 17:34:10 +0000 |
commit | 83ba6762cc43d9db581b979bb5e3445669e46cc2 (patch) | |
tree | 2e69833b43f791ed253a7a20318b767ebe56cdb8 /src/database/rrdhost.c | |
parent | Releasing debian version 1.47.5-1. (diff) | |
download | netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.tar.xz netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.zip |
Merging upstream version 2.0.3+dfsg (Closes: #923993, #1042533, #1045145).
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/database/rrdhost.c')
-rw-r--r-- | src/database/rrdhost.c | 404 |
1 files changed, 80 insertions, 324 deletions
diff --git a/src/database/rrdhost.c b/src/database/rrdhost.c index b3d786cff..1902746ee 100644 --- a/src/database/rrdhost.c +++ b/src/database/rrdhost.c @@ -36,13 +36,13 @@ time_t rrdhost_free_ephemeral_time_s = 86400; RRDHOST *find_host_by_node_id(char *node_id) { - nd_uuid_t node_uuid; - if (unlikely(!node_id || uuid_parse(node_id, node_uuid))) + ND_UUID node_uuid; + if (unlikely(!node_id || uuid_parse(node_id, node_uuid.uuid))) return NULL; RRDHOST *host, *ret = NULL; dfe_start_read(rrdhost_root_index, host) { - if (host->node_id && uuid_eq(*host->node_id, node_uuid)) { + if (UUIDeq(host->node_id, node_uuid)) { ret = host; break; } @@ -232,10 +232,10 @@ void set_host_properties(RRDHOST *host, int update_every, RRD_MEMORY_MODE memory // RRDHOST - add a host static void rrdhost_initialize_rrdpush_sender(RRDHOST *host, - unsigned int rrdpush_enabled, - char *rrdpush_destination, - char *rrdpush_api_key, - char *rrdpush_send_charts_matching + unsigned int rrdpush_enabled, + const char *rrdpush_destination, + const char *rrdpush_api_key, + const char *rrdpush_send_charts_matching ) { if(rrdhost_flag_check(host, RRDHOST_FLAG_RRDPUSH_SENDER_INITIALIZED)) return; @@ -244,15 +244,13 @@ static void rrdhost_initialize_rrdpush_sender(RRDHOST *host, rrdhost_streaming_sender_structures_init(host); -#ifdef ENABLE_HTTPS host->sender->ssl = NETDATA_SSL_UNSET_CONNECTION; -#endif - host->rrdpush_send_destination = strdupz(rrdpush_destination); + host->rrdpush.send.destination = strdupz(rrdpush_destination); rrdpush_destinations_init(host); - host->rrdpush_send_api_key = strdupz(rrdpush_api_key); - host->rrdpush_send_charts_matching = simple_pattern_create(rrdpush_send_charts_matching, NULL, + host->rrdpush.send.api_key = strdupz(rrdpush_api_key); + host->rrdpush.send.charts_matching = simple_pattern_create(rrdpush_send_charts_matching, NULL, SIMPLE_PATTERN_EXACT, true); rrdhost_option_set(host, RRDHOST_OPTION_SENDER_ENABLED); @@ -343,9 +341,9 @@ static RRDHOST *rrdhost_create( RRD_MEMORY_MODE memory_mode, unsigned int health_enabled, unsigned int rrdpush_enabled, - char *rrdpush_destination, - char *rrdpush_api_key, - char *rrdpush_send_charts_matching, + const char *rrdpush_destination, + const char *rrdpush_api_key, + const char *rrdpush_send_charts_matching, bool rrdpush_enable_replication, time_t rrdpush_seconds_to_replicate, time_t rrdpush_replication_step, @@ -383,8 +381,7 @@ static RRDHOST *rrdhost_create( host->rrd_history_entries = align_entries_to_pagesize(memory_mode, entries); host->health.health_enabled = ((memory_mode == RRD_MEMORY_MODE_NONE)) ? 0 : health_enabled; - netdata_mutex_init(&host->aclk_state_lock); - netdata_mutex_init(&host->receiver_lock); + spinlock_init(&host->receiver_lock); if (likely(!archived)) { rrd_functions_host_init(host); @@ -426,7 +423,7 @@ static RRDHOST *rrdhost_create( if(!host->rrdvars) host->rrdvars = rrdvariables_create(); - if (likely(!uuid_parse(host->machine_guid, host->host_uuid))) + if (likely(!uuid_parse(host->machine_guid, host->host_id.uuid))) sql_load_node_id(host); else error_report("Host machine GUID %s is not valid", host->machine_guid); @@ -477,7 +474,7 @@ static RRDHOST *rrdhost_create( if (is_localhost && host->system_info) { host->system_info->ml_capable = ml_capable(); host->system_info->ml_enabled = ml_enabled(host); - host->system_info->mc_version = enable_metric_correlations ? metric_correlations_version : 0; + host->system_info->mc_version = metric_correlations_version; } // ------------------------------------------------------------------------ @@ -535,8 +532,8 @@ static RRDHOST *rrdhost_create( , rrd_memory_mode_name(host->rrd_memory_mode) , host->rrd_history_entries , rrdhost_has_rrdpush_sender_enabled(host)?"enabled":"disabled" - , host->rrdpush_send_destination?host->rrdpush_send_destination:"" - , host->rrdpush_send_api_key?host->rrdpush_send_api_key:"" + , host->rrdpush.send.destination?host->rrdpush.send.destination:"" + , host->rrdpush.send.api_key?host->rrdpush.send.api_key:"" , host->health.health_enabled?"enabled":"disabled" , host->cache_dir , string2str(host->health.health_default_exec) @@ -569,9 +566,9 @@ static void rrdhost_update(RRDHOST *host , RRD_MEMORY_MODE mode , unsigned int health_enabled , unsigned int rrdpush_enabled - , char *rrdpush_destination - , char *rrdpush_api_key - , char *rrdpush_send_charts_matching + , const char *rrdpush_destination + , const char *rrdpush_api_key + , const char *rrdpush_send_charts_matching , bool rrdpush_enable_replication , time_t rrdpush_seconds_to_replicate , time_t rrdpush_replication_step @@ -709,9 +706,9 @@ RRDHOST *rrdhost_find_or_create( , RRD_MEMORY_MODE mode , unsigned int health_enabled , unsigned int rrdpush_enabled - , char *rrdpush_destination - , char *rrdpush_api_key - , char *rrdpush_send_charts_matching + , const char *rrdpush_destination + , const char *rrdpush_api_key + , const char *rrdpush_send_charts_matching , bool rrdpush_enable_replication , time_t rrdpush_seconds_to_replicate , time_t rrdpush_replication_step @@ -865,7 +862,7 @@ RRD_BACKFILL get_dbengine_backfill(RRD_BACKFILL backfill) #endif -void dbengine_init(char *hostname) { +static void dbengine_init(const char *hostname) { #ifdef ENABLE_DBENGINE use_direct_io = config_get_boolean(CONFIG_SECTION_DB, "dbengine use direct io", use_direct_io); @@ -903,10 +900,10 @@ void dbengine_init(char *hostname) { !config_exists(CONFIG_SECTION_DB, "dbengine tier 2 update every iterations") && !config_exists(CONFIG_SECTION_DB, "dbengine tier 3 update every iterations") && !config_exists(CONFIG_SECTION_DB, "dbengine tier 4 update every iterations") && - !config_exists(CONFIG_SECTION_DB, "dbengine tier 1 disk space MB") && - !config_exists(CONFIG_SECTION_DB, "dbengine tier 2 disk space MB") && - !config_exists(CONFIG_SECTION_DB, "dbengine tier 3 disk space MB") && - !config_exists(CONFIG_SECTION_DB, "dbengine tier 4 disk space MB")); + !config_exists(CONFIG_SECTION_DB, "dbengine tier 1 retention size") && + !config_exists(CONFIG_SECTION_DB, "dbengine tier 2 retention size") && + !config_exists(CONFIG_SECTION_DB, "dbengine tier 3 retention size") && + !config_exists(CONFIG_SECTION_DB, "dbengine tier 4 retention size")); default_backfill = get_dbengine_backfill(RRD_BACKFILL_NEW); char dbengineconfig[200 + 1]; @@ -928,11 +925,11 @@ void dbengine_init(char *hostname) { storage_tiers_grouping_iterations[tier] = grouping_iterations; } - default_multidb_disk_quota_mb = (int) config_get_number(CONFIG_SECTION_DB, "dbengine tier 0 disk space MB", RRDENG_DEFAULT_TIER_DISK_SPACE_MB); + default_multidb_disk_quota_mb = (int) config_get_size_mb(CONFIG_SECTION_DB, "dbengine tier 0 retention size", RRDENG_DEFAULT_TIER_DISK_SPACE_MB); if(default_multidb_disk_quota_mb && default_multidb_disk_quota_mb < RRDENG_MIN_DISK_SPACE_MB) { netdata_log_error("Invalid disk space %d for tier 0 given. Defaulting to %d.", default_multidb_disk_quota_mb, RRDENG_MIN_DISK_SPACE_MB); default_multidb_disk_quota_mb = RRDENG_MIN_DISK_SPACE_MB; - config_set_number(CONFIG_SECTION_DB, "dbengine tier 0 disk space MB", default_multidb_disk_quota_mb); + config_set_size_mb(CONFIG_SECTION_DB, "dbengine tier 0 retention size", default_multidb_disk_quota_mb); } #ifdef OS_WINDOWS @@ -962,11 +959,11 @@ void dbengine_init(char *hostname) { } int disk_space_mb = tier ? RRDENG_DEFAULT_TIER_DISK_SPACE_MB : default_multidb_disk_quota_mb; - snprintfz(dbengineconfig, sizeof(dbengineconfig) - 1, "dbengine tier %zu disk space MB", tier); - disk_space_mb = config_get_number(CONFIG_SECTION_DB, dbengineconfig, disk_space_mb); + snprintfz(dbengineconfig, sizeof(dbengineconfig) - 1, "dbengine tier %zu retention size", tier); + disk_space_mb = config_get_size_mb(CONFIG_SECTION_DB, dbengineconfig, disk_space_mb); - snprintfz(dbengineconfig, sizeof(dbengineconfig) - 1, "dbengine tier %zu retention days", tier); - storage_tiers_retention_days[tier] = config_get_number( + snprintfz(dbengineconfig, sizeof(dbengineconfig) - 1, "dbengine tier %zu retention time", tier); + storage_tiers_retention_days[tier] = config_get_duration_days( CONFIG_SECTION_DB, dbengineconfig, new_dbengine_defaults ? storage_tiers_retention_days[tier] : 0); tiers_init[tier].disk_space_mb = (int) disk_space_mb; @@ -1027,12 +1024,14 @@ void dbengine_init(char *hostname) { #endif } -int rrd_init(char *hostname, struct rrdhost_system_info *system_info, bool unittest) { +void api_v1_management_init(void); + +int rrd_init(const char *hostname, struct rrdhost_system_info *system_info, bool unittest) { rrdhost_init(); if (unlikely(sql_init_meta_database(DB_CHECK_NONE, system_info ? 0 : 1))) { if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) { - set_late_global_environment(system_info); + set_late_analytics_variables(system_info); fatal("Failed to initialize SQLite"); } @@ -1048,9 +1047,9 @@ int rrd_init(char *hostname, struct rrdhost_system_info *system_info, bool unitt dbengine_enabled = true; } else { - rrdpush_init(); + stream_conf_init(); - if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE || rrdpush_receiver_needs_dbengine()) { + if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE || stream_conf_receiver_needs_dbengine()) { nd_log(NDLS_DAEMON, NDLP_DEBUG, "DBENGINE: Initializing ..."); @@ -1095,14 +1094,14 @@ int rrd_init(char *hostname, struct rrdhost_system_info *system_info, bool unitt , default_rrd_history_entries , default_rrd_memory_mode , health_plugin_enabled() - , default_rrdpush_enabled - , default_rrdpush_destination - , default_rrdpush_api_key - , default_rrdpush_send_charts_matching - , default_rrdpush_enable_replication - , default_rrdpush_seconds_to_replicate - , default_rrdpush_replication_step - , system_info + , + stream_conf_send_enabled, + stream_conf_send_destination, + stream_conf_send_api_key, + stream_conf_send_charts_matching, + stream_conf_replication_enabled, + stream_conf_replication_period, + stream_conf_replication_step, system_info , 1 , 0 ); @@ -1112,26 +1111,15 @@ int rrd_init(char *hostname, struct rrdhost_system_info *system_info, bool unitt dyncfg_host_init(localhost); - if(!unittest) { + if(!unittest) health_plugin_init(); - } - - // we register this only on localhost - // for the other nodes, the origin server should register it - rrd_function_add_inline(localhost, NULL, "streaming", 10, - RRDFUNCTIONS_PRIORITY_DEFAULT + 1, RRDFUNCTIONS_STREAMING_HELP, "top", - HTTP_ACCESS_SIGNED_ID | HTTP_ACCESS_SAME_SPACE | HTTP_ACCESS_SENSITIVE_DATA, - rrdhost_function_streaming); - rrd_function_add_inline(localhost, NULL, "netdata-api-calls", 10, - RRDFUNCTIONS_PRIORITY_DEFAULT + 2, RRDFUNCTIONS_PROGRESS_HELP, "top", - HTTP_ACCESS_SIGNED_ID | HTTP_ACCESS_SAME_SPACE | HTTP_ACCESS_SENSITIVE_DATA, - rrdhost_function_progress); + global_functions_add(); if (likely(system_info)) { - detect_machine_guid_change(&localhost->host_uuid); + detect_machine_guid_change(&localhost->host_id.uuid); sql_aclk_sync_init(); - web_client_api_v1_management_init(); + api_v1_management_init(); } return 0; @@ -1155,6 +1143,7 @@ void rrdhost_system_info_free(struct rrdhost_system_info *system_info) { freez(system_info->host_os_detection); freez(system_info->host_cores); freez(system_info->host_cpu_freq); + freez(system_info->host_cpu_model); freez(system_info->host_ram_total); freez(system_info->host_disk_space); freez(system_info->container_os_name); @@ -1195,7 +1184,7 @@ static void rrdhost_streaming_sender_structures_init(RRDHOST *host) host->sender->rrdpush_sender_socket = -1; host->sender->disabled_capabilities = STREAM_CAP_NONE; - if(!default_rrdpush_compression_enabled) + if(!stream_conf_compression_enabled) host->sender->disabled_capabilities |= STREAM_CAP_COMPRESSIONS_AVAILABLE; spinlock_init(&host->sender->spinlock); @@ -1242,6 +1231,10 @@ void rrdhost_free___while_having_rrd_wrlock(RRDHOST *host, bool force) { } // ------------------------------------------------------------------------ + + rrdhost_stream_path_clear(host, true); + + // ------------------------------------------------------------------------ // clean up streaming chart slots rrdhost_pluginsd_send_chart_slots_free(host); @@ -1284,9 +1277,6 @@ void rrdhost_free___while_having_rrd_wrlock(RRDHOST *host, bool force) { // ------------------------------------------------------------------------ // free it - pthread_mutex_destroy(&host->aclk_state_lock); - freez(host->aclk_state.claimed_id); - freez(host->aclk_state.prev_claimed_id); rrdlabels_destroy(host->rrdlabels); string_freez(host->os); string_freez(host->timezone); @@ -1295,14 +1285,13 @@ void rrdhost_free___while_having_rrd_wrlock(RRDHOST *host, bool force) { string_freez(host->program_version); rrdhost_system_info_free(host->system_info); freez(host->cache_dir); - freez(host->rrdpush_send_api_key); - freez(host->rrdpush_send_destination); + freez(host->rrdpush.send.api_key); + freez(host->rrdpush.send.destination); rrdpush_destinations_free(host); string_freez(host->health.health_default_exec); string_freez(host->health.health_default_recipient); string_freez(host->registry_hostname); - simple_pattern_free(host->rrdpush_send_charts_matching); - freez(host->node_id); + simple_pattern_free(host->rrdpush.send.charts_matching); rrd_functions_host_destroy(host); rrdvariables_destroy(host->rrdvars); @@ -1350,6 +1339,7 @@ struct rrdhost_system_info *rrdhost_labels_to_system_info(RRDLABELS *labels) { rrdlabels_get_value_strdup_or_null(labels, &info->kernel_version, "_kernel_version"); rrdlabels_get_value_strdup_or_null(labels, &info->host_cores, "_system_cores"); rrdlabels_get_value_strdup_or_null(labels, &info->host_cpu_freq, "_system_cpu_freq"); + rrdlabels_get_value_strdup_or_null(labels, &info->host_cpu_model, "_system_cpu_model"); rrdlabels_get_value_strdup_or_null(labels, &info->host_ram_total, "_system_ram_total"); rrdlabels_get_value_strdup_or_null(labels, &info->host_disk_space, "_system_disk_space"); rrdlabels_get_value_strdup_or_null(labels, &info->architecture, "_architecture"); @@ -1392,6 +1382,9 @@ static void rrdhost_load_auto_labels(void) { if (localhost->system_info->host_cpu_freq) rrdlabels_add(labels, "_system_cpu_freq", localhost->system_info->host_cpu_freq, RRDLABEL_SRC_AUTO); + if (localhost->system_info->host_cpu_model) + rrdlabels_add(labels, "_system_cpu_model", localhost->system_info->host_cpu_model, RRDLABEL_SRC_AUTO); + if (localhost->system_info->host_ram_total) rrdlabels_add(labels, "_system_ram_total", localhost->system_info->host_ram_total, RRDLABEL_SRC_AUTO); @@ -1441,8 +1434,8 @@ static void rrdhost_load_auto_labels(void) { rrdlabels_add(labels, "_hostname", string2str(localhost->hostname), RRDLABEL_SRC_AUTO); rrdlabels_add(labels, "_os", string2str(localhost->os), RRDLABEL_SRC_AUTO); - if (localhost->rrdpush_send_destination) - rrdlabels_add(labels, "_streams_to", localhost->rrdpush_send_destination, RRDLABEL_SRC_AUTO); + if (localhost->rrdpush.send.destination) + rrdlabels_add(labels, "_streams_to", localhost->rrdpush.send.destination, RRDLABEL_SRC_AUTO); } void rrdhost_set_is_parent_label(void) { @@ -1453,14 +1446,15 @@ void rrdhost_set_is_parent_label(void) { rrdlabels_add(labels, "_is_parent", (count) ? "true" : "false", RRDLABEL_SRC_AUTO); //queue a node info -#ifdef ENABLE_ACLK - if (netdata_cloud_enabled) { - aclk_queue_node_info(localhost, false); - } -#endif + aclk_queue_node_info(localhost, false); } } +static bool config_label_cb(void *data __maybe_unused, const char *name, const char *value) { + rrdlabels_add(localhost->rrdlabels, name, value, RRDLABEL_SRC_CONFIG); + return true; +} + static void rrdhost_load_config_labels(void) { int status = config_load(NULL, 1, CONFIG_SECTION_HOST_LABEL); if(!status) { @@ -1470,16 +1464,7 @@ static void rrdhost_load_config_labels(void) { filename); } - struct section *co = appconfig_get_section(&netdata_config, CONFIG_SECTION_HOST_LABEL); - if(co) { - config_section_wrlock(co); - struct config_option *cv; - for(cv = co->values; cv ; cv = cv->next) { - rrdlabels_add(localhost->rrdlabels, cv->name, cv->value, RRDLABEL_SRC_CONFIG); - cv->flags |= CONFIG_VALUE_USED; - } - config_section_unlock(co); - } + appconfig_foreach_value_in_section(&netdata_config, CONFIG_SECTION_HOST_LABEL, config_label_cb, NULL); } static void rrdhost_load_kubernetes_labels(void) { @@ -1498,7 +1483,7 @@ static void rrdhost_load_kubernetes_labels(void) { if(!instance) return; char buffer[1000 + 1]; - while (fgets(buffer, 1000, instance->child_stdout_fp) != NULL) + while (fgets(buffer, 1000, spawn_popen_stdout(instance)) != NULL) rrdlabels_add_pair(localhost->rrdlabels, buffer, RRDLABEL_SRC_AUTO|RRDLABEL_SRC_K8S); // Non-zero exit code means that all the script output is error messages. We've shown already any message that didn't include a ':' @@ -1624,6 +1609,10 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch freez(system_info->host_cpu_freq); system_info->host_cpu_freq = strdupz(value); } + else if (!strcmp(name, "NETDATA_SYSTEM_CPU_MODEL")){ + freez(system_info->host_cpu_model); + system_info->host_cpu_model = strdupz(value); + } else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_RAM")){ freez(system_info->host_ram_total); system_info->host_ram_total = strdupz(value); @@ -1662,8 +1651,6 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch } else if (!strcmp(name, "NETDATA_SYSTEM_CPU_VENDOR")) return res; - else if (!strcmp(name, "NETDATA_SYSTEM_CPU_MODEL")) - return res; else if (!strcmp(name, "NETDATA_SYSTEM_CPU_DETECTION")) return res; else if (!strcmp(name, "NETDATA_SYSTEM_RAM_DETECTION")) @@ -1679,239 +1666,8 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch return res; } -static NETDATA_DOUBLE rrdhost_sender_replication_completion_unsafe(RRDHOST *host, time_t now, size_t *instances) { - size_t charts = rrdhost_sender_replicating_charts(host); - NETDATA_DOUBLE completion; - if(!charts || !host->sender || !host->sender->replication.oldest_request_after_t) - completion = 100.0; - else if(!host->sender->replication.latest_completed_before_t || host->sender->replication.latest_completed_before_t < host->sender->replication.oldest_request_after_t) - completion = 0.0; - else { - time_t total = now - host->sender->replication.oldest_request_after_t; - time_t current = host->sender->replication.latest_completed_before_t - host->sender->replication.oldest_request_after_t; - completion = (NETDATA_DOUBLE) current * 100.0 / (NETDATA_DOUBLE) total; - } - - *instances = charts; - - return completion; -} - bool rrdhost_matches_window(RRDHOST *host, time_t after, time_t before, time_t now) { time_t first_time_s, last_time_s; rrdhost_retention(host, now, rrdhost_is_online(host), &first_time_s, &last_time_s); return query_matches_retention(after, before, first_time_s, last_time_s, 0); } - -bool rrdhost_state_cloud_emulation(RRDHOST *host) { - return rrdhost_is_online(host); -} - -void rrdhost_status(RRDHOST *host, time_t now, RRDHOST_STATUS *s) { - memset(s, 0, sizeof(*s)); - - s->host = host; - s->now = now; - - RRDHOST_FLAGS flags = __atomic_load_n(&host->flags, __ATOMIC_RELAXED); - - // --- dyncfg --- - - s->dyncfg.status = dyncfg_available_for_rrdhost(host) ? RRDHOST_DYNCFG_STATUS_AVAILABLE : RRDHOST_DYNCFG_STATUS_UNAVAILABLE; - - // --- db --- - - bool online = rrdhost_is_online(host); - - rrdhost_retention(host, now, online, &s->db.first_time_s, &s->db.last_time_s); - s->db.metrics = host->rrdctx.metrics; - s->db.instances = host->rrdctx.instances; - s->db.contexts = dictionary_entries(host->rrdctx.contexts); - if(!s->db.first_time_s || !s->db.last_time_s || !s->db.metrics || !s->db.instances || !s->db.contexts || - (flags & (RRDHOST_FLAG_PENDING_CONTEXT_LOAD))) - s->db.status = RRDHOST_DB_STATUS_INITIALIZING; - else - s->db.status = RRDHOST_DB_STATUS_QUERYABLE; - - s->db.mode = host->rrd_memory_mode; - - // --- ingest --- - - s->ingest.since = MAX(host->child_connect_time, host->child_disconnected_time); - s->ingest.reason = (online) ? STREAM_HANDSHAKE_NEVER : host->rrdpush_last_receiver_exit_reason; - - netdata_mutex_lock(&host->receiver_lock); - s->ingest.hops = (host->system_info ? host->system_info->hops : (host == localhost) ? 0 : 1); - bool has_receiver = false; - if (host->receiver) { - has_receiver = true; - s->ingest.replication.instances = rrdhost_receiver_replicating_charts(host); - s->ingest.replication.completion = host->rrdpush_receiver_replication_percent; - s->ingest.replication.in_progress = s->ingest.replication.instances > 0; - - s->ingest.capabilities = host->receiver->capabilities; - s->ingest.peers = socket_peers(host->receiver->fd); -#ifdef ENABLE_HTTPS - s->ingest.ssl = SSL_connection(&host->receiver->ssl); -#endif - } - netdata_mutex_unlock(&host->receiver_lock); - - if (online) { - if(s->db.status == RRDHOST_DB_STATUS_INITIALIZING) - s->ingest.status = RRDHOST_INGEST_STATUS_INITIALIZING; - - else if (host == localhost || rrdhost_option_check(host, RRDHOST_OPTION_VIRTUAL_HOST)) { - s->ingest.status = RRDHOST_INGEST_STATUS_ONLINE; - s->ingest.since = netdata_start_time; - } - - else if (s->ingest.replication.in_progress) - s->ingest.status = RRDHOST_INGEST_STATUS_REPLICATING; - - else - s->ingest.status = RRDHOST_INGEST_STATUS_ONLINE; - } - else { - if (!s->ingest.since) { - s->ingest.status = RRDHOST_INGEST_STATUS_ARCHIVED; - s->ingest.since = s->db.last_time_s; - } - - else - s->ingest.status = RRDHOST_INGEST_STATUS_OFFLINE; - } - - if(host == localhost) - s->ingest.type = RRDHOST_INGEST_TYPE_LOCALHOST; - else if(has_receiver || rrdhost_flag_set(host, RRDHOST_FLAG_RRDPUSH_RECEIVER_DISCONNECTED)) - s->ingest.type = RRDHOST_INGEST_TYPE_CHILD; - else if(rrdhost_option_check(host, RRDHOST_OPTION_VIRTUAL_HOST)) - s->ingest.type = RRDHOST_INGEST_TYPE_VIRTUAL; - else - s->ingest.type = RRDHOST_INGEST_TYPE_ARCHIVED; - - s->ingest.id = host->rrdpush_receiver_connection_counter; - - if(!s->ingest.since) - s->ingest.since = netdata_start_time; - - if(s->ingest.status == RRDHOST_INGEST_STATUS_ONLINE) - s->db.liveness = RRDHOST_DB_LIVENESS_LIVE; - else - s->db.liveness = RRDHOST_DB_LIVENESS_STALE; - - // --- stream --- - - if (!host->sender) { - s->stream.status = RRDHOST_STREAM_STATUS_DISABLED; - s->stream.hops = s->ingest.hops + 1; - } - else { - sender_lock(host->sender); - - s->stream.since = host->sender->last_state_since_t; - s->stream.peers = socket_peers(host->sender->rrdpush_sender_socket); -#ifdef ENABLE_HTTPS - s->stream.ssl = SSL_connection(&host->sender->ssl); -#endif - - memcpy(s->stream.sent_bytes_on_this_connection_per_type, - host->sender->sent_bytes_on_this_connection_per_type, - MIN(sizeof(s->stream.sent_bytes_on_this_connection_per_type), - sizeof(host->sender->sent_bytes_on_this_connection_per_type))); - - if (rrdhost_flag_check(host, RRDHOST_FLAG_RRDPUSH_SENDER_CONNECTED)) { - s->stream.hops = host->sender->hops; - s->stream.reason = STREAM_HANDSHAKE_NEVER; - s->stream.capabilities = host->sender->capabilities; - - s->stream.replication.completion = rrdhost_sender_replication_completion_unsafe(host, now, &s->stream.replication.instances); - s->stream.replication.in_progress = s->stream.replication.instances > 0; - - if(s->stream.replication.in_progress) - s->stream.status = RRDHOST_STREAM_STATUS_REPLICATING; - else - s->stream.status = RRDHOST_STREAM_STATUS_ONLINE; - - s->stream.compression = host->sender->compressor.initialized; - } - else { - s->stream.status = RRDHOST_STREAM_STATUS_OFFLINE; - s->stream.hops = s->ingest.hops + 1; - s->stream.reason = host->sender->exit.reason; - } - - sender_unlock(host->sender); - } - - s->stream.id = host->rrdpush_sender_connection_counter; - - if(!s->stream.since) - s->stream.since = netdata_start_time; - - // --- ml --- - - if(ml_host_get_host_status(host, &s->ml.metrics)) { - s->ml.type = RRDHOST_ML_TYPE_SELF; - - if(s->ingest.status == RRDHOST_INGEST_STATUS_OFFLINE || s->ingest.status == RRDHOST_INGEST_STATUS_ARCHIVED) - s->ml.status = RRDHOST_ML_STATUS_OFFLINE; - else - s->ml.status = RRDHOST_ML_STATUS_RUNNING; - } - else if(stream_has_capability(&s->ingest, STREAM_CAP_DATA_WITH_ML)) { - s->ml.type = RRDHOST_ML_TYPE_RECEIVED; - s->ml.status = RRDHOST_ML_STATUS_RUNNING; - } - else { - // does not receive ML, does not run ML - s->ml.type = RRDHOST_ML_TYPE_DISABLED; - s->ml.status = RRDHOST_ML_STATUS_DISABLED; - } - - // --- health --- - - if(host->health.health_enabled) { - if(flags & RRDHOST_FLAG_PENDING_HEALTH_INITIALIZATION) - s->health.status = RRDHOST_HEALTH_STATUS_INITIALIZING; - else { - s->health.status = RRDHOST_HEALTH_STATUS_RUNNING; - - RRDCALC *rc; - foreach_rrdcalc_in_rrdhost_read(host, rc) { - if (unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec)) - continue; - - switch (rc->status) { - default: - case RRDCALC_STATUS_REMOVED: - break; - - case RRDCALC_STATUS_CLEAR: - s->health.alerts.clear++; - break; - - case RRDCALC_STATUS_WARNING: - s->health.alerts.warning++; - break; - - case RRDCALC_STATUS_CRITICAL: - s->health.alerts.critical++; - break; - - case RRDCALC_STATUS_UNDEFINED: - s->health.alerts.undefined++; - break; - - case RRDCALC_STATUS_UNINITIALIZED: - s->health.alerts.uninitialized++; - break; - } - } - foreach_rrdcalc_in_rrdhost_done(rc); - } - } - else - s->health.status = RRDHOST_HEALTH_STATUS_DISABLED; -} |