summaryrefslogtreecommitdiffstats
path: root/database/rrdhost.c
diff options
context:
space:
mode:
Diffstat (limited to 'database/rrdhost.c')
-rw-r--r--database/rrdhost.c127
1 files changed, 110 insertions, 17 deletions
diff --git a/database/rrdhost.c b/database/rrdhost.c
index 5ce5366d2..d9608b740 100644
--- a/database/rrdhost.c
+++ b/database/rrdhost.c
@@ -88,13 +88,20 @@ static inline void rrdhost_init_os(RRDHOST *host, const char *os) {
freez(old);
}
-static inline void rrdhost_init_timezone(RRDHOST *host, const char *timezone) {
- if(host->timezone && timezone && !strcmp(host->timezone, timezone))
+static inline void rrdhost_init_timezone(RRDHOST *host, const char *timezone, const char *abbrev_timezone, int32_t utc_offset) {
+ if (host->timezone && timezone && !strcmp(host->timezone, timezone) && host->abbrev_timezone && abbrev_timezone &&
+ !strcmp(host->abbrev_timezone, abbrev_timezone) && host->utc_offset == utc_offset)
return;
void *old = (void *)host->timezone;
host->timezone = strdupz((timezone && *timezone)?timezone:"unknown");
freez(old);
+
+ old = (void *)host->abbrev_timezone;
+ host->abbrev_timezone = strdupz((abbrev_timezone && *abbrev_timezone) ? abbrev_timezone : "UTC");
+ freez(old);
+
+ host->utc_offset = utc_offset;
}
static inline void rrdhost_init_machine_guid(RRDHOST *host, const char *machine_guid) {
@@ -105,7 +112,8 @@ static inline void rrdhost_init_machine_guid(RRDHOST *host, const char *machine_
void set_host_properties(RRDHOST *host, int update_every, RRD_MEMORY_MODE memory_mode, const char *hostname,
const char *registry_hostname, const char *guid, const char *os, const char *tags,
- const char *tzone, const char *program_name, const char *program_version)
+ const char *tzone, const char *abbrev_tzone, int32_t utc_offset, const char *program_name,
+ const char *program_version)
{
host->rrd_update_every = update_every;
@@ -116,7 +124,7 @@ void set_host_properties(RRDHOST *host, int update_every, RRD_MEMORY_MODE memory
rrdhost_init_machine_guid(host, guid);
rrdhost_init_os(host, os);
- rrdhost_init_timezone(host, tzone);
+ rrdhost_init_timezone(host, tzone, abbrev_tzone, utc_offset);
rrdhost_init_tags(host, tags);
host->program_name = strdupz((program_name && *program_name) ? program_name : "unknown");
@@ -133,6 +141,8 @@ RRDHOST *rrdhost_create(const char *hostname,
const char *guid,
const char *os,
const char *timezone,
+ const char *abbrev_timezone,
+ int32_t utc_offset,
const char *tags,
const char *program_name,
const char *program_version,
@@ -160,7 +170,7 @@ RRDHOST *rrdhost_create(const char *hostname,
RRDHOST *host = callocz(1, sizeof(RRDHOST));
set_host_properties(host, (update_every > 0)?update_every:1, memory_mode, hostname, registry_hostname, guid, os,
- tags, timezone, program_name, program_version);
+ tags, timezone, abbrev_timezone, utc_offset, program_name, program_version);
host->rrd_history_entries = align_entries_to_pagesize(memory_mode, entries);
host->health_enabled = ((memory_mode == RRD_MEMORY_MODE_NONE)) ? 0 : health_enabled;
@@ -285,9 +295,6 @@ RRDHOST *rrdhost_create(const char *hostname,
rrdhost_wrlock(host);
health_readdir(host, health_user_config_dir(), health_stock_config_dir(), NULL);
rrdhost_unlock(host);
-
- health_alarm_log_load(host);
- health_alarm_log_open(host);
}
RRDHOST *t = rrdhost_index_add(host);
@@ -303,6 +310,23 @@ RRDHOST *rrdhost_create(const char *hostname,
if (unlikely(rc))
error_report("Failed to store machine GUID to the database");
sql_load_node_id(host);
+ if (host->health_enabled) {
+ if (!file_is_migrated(host->health_log_filename)) {
+ int rc = sql_create_health_log_table(host);
+ if (unlikely(rc)) {
+ error_report("Failed to create health log table in the database");
+ health_alarm_log_load(host);
+ health_alarm_log_open(host);
+ }
+ else {
+ health_alarm_log_load(host);
+ add_migrated_file(host->health_log_filename, 0);
+ }
+ } else {
+ sql_create_health_log_table(host);
+ sql_health_alarm_log_load(host);
+ }
+ }
}
else
error_report("Host machine GUID %s is not valid", host->machine_guid);
@@ -358,6 +382,8 @@ RRDHOST *rrdhost_create(const char *hostname,
else localhost = host;
}
+ ml_new_host(host);
+
info("Host '%s' (at registry as '%s') with guid '%s' initialized"
", os '%s'"
", timezone '%s'"
@@ -408,6 +434,8 @@ void rrdhost_update(RRDHOST *host
, const char *guid
, const char *os
, const char *timezone
+ , const char *abbrev_timezone
+ , int32_t utc_offset
, const char *tags
, const char *program_name
, const char *program_version
@@ -435,7 +463,7 @@ void rrdhost_update(RRDHOST *host
host->system_info = system_info;
rrdhost_init_os(host, os);
- rrdhost_init_timezone(host, timezone);
+ rrdhost_init_timezone(host, timezone, abbrev_timezone, utc_offset);
freez(host->registry_hostname);
host->registry_hostname = strdupz((registry_hostname && *registry_hostname)?registry_hostname:hostname);
@@ -494,8 +522,21 @@ void rrdhost_update(RRDHOST *host
health_readdir(host, health_user_config_dir(), health_stock_config_dir(), NULL);
rrdhost_unlock(host);
- health_alarm_log_load(host);
- health_alarm_log_open(host);
+ if (!file_is_migrated(host->health_log_filename)) {
+ int rc = sql_create_health_log_table(host);
+ if (unlikely(rc)) {
+ error_report("Failed to create health log table in the database");
+
+ health_alarm_log_load(host);
+ health_alarm_log_open(host);
+ } else {
+ health_alarm_log_load(host);
+ add_migrated_file(host->health_log_filename, 0);
+ }
+ } else {
+ sql_create_health_log_table(host);
+ sql_health_alarm_log_load(host);
+ }
}
rrd_hosts_available++;
info("Host %s is not in archived mode anymore", host->hostname);
@@ -510,6 +551,8 @@ RRDHOST *rrdhost_find_or_create(
, const char *guid
, const char *os
, const char *timezone
+ , const char *abbrev_timezone
+ , int32_t utc_offset
, const char *tags
, const char *program_name
, const char *program_version
@@ -541,6 +584,8 @@ RRDHOST *rrdhost_find_or_create(
, guid
, os
, timezone
+ , abbrev_timezone
+ , utc_offset
, tags
, program_name
, program_version
@@ -563,6 +608,8 @@ RRDHOST *rrdhost_find_or_create(
, guid
, os
, timezone
+ , abbrev_timezone
+ , utc_offset
, tags
, program_name
, program_version
@@ -632,13 +679,20 @@ restart_after_removal:
int rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
rrdset_free_obsolete_time = config_get_number(CONFIG_SECTION_GLOBAL, "cleanup obsolete charts after seconds", rrdset_free_obsolete_time);
+ // Current chart locking and invalidation scheme doesn't prevent Netdata from segmentation faults if a short
+ // cleanup delay is set. Extensive stress tests showed that 10 seconds is quite a safe delay. Look at
+ // https://github.com/netdata/netdata/pull/11222#issuecomment-868367920 for more information.
+ if (rrdset_free_obsolete_time < 10) {
+ rrdset_free_obsolete_time = 10;
+ info("The \"cleanup obsolete charts after seconds\" option was set to 10 seconds. A lower delay can potentially cause a segmentation fault.");
+ }
gap_when_lost_iterations_above = (int)config_get_number(CONFIG_SECTION_GLOBAL, "gap when lost iterations above", gap_when_lost_iterations_above);
if (gap_when_lost_iterations_above < 1)
gap_when_lost_iterations_above = 1;
- if (unlikely(sql_init_database())) {
+ if (unlikely(sql_init_database(DB_CHECK_NONE))) {
if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE)
- return 1;
+ fatal("Failed to initialize SQLite");
info("Skipping SQLITE metadata initialization since memory mode is not db engine");
}
@@ -654,6 +708,8 @@ int rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
, registry_get_this_machine_guid()
, os_type
, netdata_configured_timezone
+ , netdata_configured_abbrev_timezone
+ , netdata_configured_utc_offset
, config_get(CONFIG_SECTION_BACKEND, "host tags", "")
, program_name
, program_version
@@ -689,9 +745,10 @@ int rrd_init(char *hostname, struct rrdhost_system_info *system_info) {
rrdhost_free(localhost);
localhost = NULL;
rrd_unlock();
- return 1;
+ fatal("Failed to initialize dbengine");
}
#endif
+ sql_aclk_sync_init();
rrd_unlock();
web_client_api_v1_management_init();
@@ -849,6 +906,8 @@ void rrdhost_free(RRDHOST *host) {
rrdeng_exit(host->rrdeng_ctx);
#endif
+ ml_delete_host(host);
+
// ------------------------------------------------------------------------
// remove it from the indexes
@@ -883,6 +942,7 @@ void rrdhost_free(RRDHOST *host) {
free_label_list(host->labels.head);
freez((void *)host->os);
freez((void *)host->timezone);
+ freez((void *)host->abbrev_timezone);
freez(host->program_version);
freez(host->program_name);
rrdhost_system_info_free(host->system_info);
@@ -1371,6 +1431,7 @@ restart_after_removal:
&& st->last_updated.tv_sec + rrdset_free_obsolete_time < now
&& st->last_collected_time.tv_sec + rrdset_free_obsolete_time < now
)) {
+ st->rrdhost->obsolete_charts_count--;
#ifdef ENABLE_DBENGINE
if(st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
RRDDIM *rd, *last;
@@ -1386,6 +1447,11 @@ restart_after_removal:
continue;
}
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_ACLK)) {
+ last = rd;
+ rd = rd->next;
+ continue;
+ }
rrddim_flag_set(rd, RRDDIM_FLAG_ARCHIVED);
while (rd->variables)
rrddimvar_free(rd->variables);
@@ -1396,7 +1462,7 @@ restart_after_removal:
uint8_t can_delete_metric = rd->state->collect_ops.finalize(rd);
if (can_delete_metric) {
/* This metric has no data and no references */
- delete_dimension_uuid(rd->state->metric_uuid);
+ delete_dimension_uuid(&rd->state->metric_uuid);
rrddim_free(st, rd);
if (unlikely(!last)) {
rd = st->dimensions;
@@ -1416,6 +1482,7 @@ restart_after_removal:
rrdvar_free_remaining_variables(host, &st->rrdvar_root_index);
rrdset_flag_clear(st, RRDSET_FLAG_OBSOLETE);
+
if (st->dimensions) {
/* If the chart still has dimensions don't delete it from the metadata log */
continue;
@@ -1437,6 +1504,30 @@ restart_after_removal:
}
}
+void rrd_cleanup_obsolete_charts()
+{
+ rrd_rdlock();
+
+ RRDHOST *host;
+ rrdhost_foreach_read(host)
+ {
+ if (host->obsolete_charts_count) {
+ rrdhost_wrlock(host);
+#ifdef ENABLE_ACLK
+ host->deleted_charts_count = 0;
+#endif
+ rrdhost_cleanup_obsolete_charts(host);
+#ifdef ENABLE_ACLK
+ if (host->deleted_charts_count)
+ aclk_update_chart(host, "dummy-chart", 0);
+#endif
+ rrdhost_unlock(host);
+ }
+ }
+
+ rrd_unlock();
+}
+
// ----------------------------------------------------------------------------
// RRDHOST - set system info from environment variables
// system_info fields must be heap allocated or NULL
@@ -1466,8 +1557,8 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch
system_info->container_os_version_id = strdupz(value);
}
else if(!strcmp(name, "NETDATA_CONTAINER_OS_DETECTION")){
- freez(system_info->host_os_detection);
- system_info->host_os_detection = strdupz(value);
+ freez(system_info->container_os_detection);
+ system_info->container_os_detection = strdupz(value);
}
else if(!strcmp(name, "NETDATA_HOST_OS_NAME")){
freez(system_info->host_os_name);
@@ -1551,6 +1642,8 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch
return res;
else if (!strcmp(name, "NETDATA_SYSTEM_DISK_DETECTION"))
return res;
+ else if (!strcmp(name, "NETDATA_CONTAINER_IS_OFFICIAL_IMAGE"))
+ return res;
else {
res = 1;
}