diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-02-09 20:27:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-09 20:27:05 +0200 |
commit | 414f416c5d290db3c3eed9073258c834fac7f2f7 (patch) | |
tree | aeed0a2619a1f42c60ec816311d1dd10c8e5ccc1 /database | |
parent | 8043106b60ec3d8d32b3a9ff3ef53991e73d9037 (diff) |
Virtual hosts for data collection (#14464)
* support multiple hosts at pluginsd structures
* cleanup obsolete code
* use a lookup hashtable to quickly find the keyword to execute, without traversing the whole linked list of keywords
* more cleanup
* move new hash function to inlined.h
* minimize comparisons, eliminate a pre-parsing of the first keyword for each line
* cleanup parser from old code
* move parser into libnetdata
* unique entries in parser keywords hashtable
* move all hashing functions to inlined.h, name their sources, simple_hash() now defaults to FNV1a, it was FNV1
* small_hash() for parser
* plugins.d now can switch hosts, and also create/update them
* update hash function and hashtable size
* updated message
* unittest all hashing functions
* reset the chart when setting a new host
* remove host tags
* enable archived hosts when a collector pushes host info
* do not need localhost to swtich to localhost
* disable ARAL and OWA with -DFSANITIZE_ADDRESS=1
Diffstat (limited to 'database')
-rw-r--r-- | database/rrd.h | 4 | ||||
-rw-r--r-- | database/rrdcalc.c | 2 | ||||
-rw-r--r-- | database/rrdhost.c | 33 | ||||
-rw-r--r-- | database/rrdlabels.c | 2 |
4 files changed, 34 insertions, 7 deletions
diff --git a/database/rrd.h b/database/rrd.h index 60be22a677..d138442124 100644 --- a/database/rrd.h +++ b/database/rrd.h @@ -279,7 +279,7 @@ void rrdlabels_destroy(DICTIONARY *labels_dict); void rrdlabels_add(DICTIONARY *dict, const char *name, const char *value, RRDLABEL_SRC ls); void rrdlabels_add_pair(DICTIONARY *dict, const char *string, RRDLABEL_SRC ls); void rrdlabels_get_value_to_buffer_or_null(DICTIONARY *labels, BUFFER *wb, const char *key, const char *quote, const char *null); -void rrdlabels_get_value_to_char_or_null(DICTIONARY *labels, char **value, const char *key); +void rrdlabels_get_value_strdup_or_null(DICTIONARY *labels, char **value, const char *key); void rrdlabels_flush(DICTIONARY *labels_dict); void rrdlabels_unmark_all(DICTIONARY *labels); @@ -961,6 +961,8 @@ struct rrdhost_system_info { int mc_version; }; +struct rrdhost_system_info *rrdhost_labels_to_system_info(DICTIONARY *labels); + struct rrdhost { char machine_guid[GUID_LEN + 1]; // the unique ID of this host diff --git a/database/rrdcalc.c b/database/rrdcalc.c index 1bfd502848..e25a22805a 100644 --- a/database/rrdcalc.c +++ b/database/rrdcalc.c @@ -100,7 +100,7 @@ static STRING *rrdcalc_replace_variables_with_rrdset_labels(const char *line, RR label_val[i - RRDCALC_VAR_LABEL_LEN - 1] = '\0'; if(likely(rc->rrdset && rc->rrdset->rrdlabels)) { - rrdlabels_get_value_to_char_or_null(rc->rrdset->rrdlabels, &lbl_value, label_val); + rrdlabels_get_value_strdup_or_null(rc->rrdset->rrdlabels, &lbl_value, label_val); if (lbl_value) { char *buf = find_and_replace(temp, var, lbl_value, m); freez(temp); diff --git a/database/rrdhost.c b/database/rrdhost.c index f9a657a248..ee7503c4fc 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -1279,6 +1279,33 @@ void rrdhost_save_charts(RRDHOST *host) { rrdset_foreach_done(st); } +struct rrdhost_system_info *rrdhost_labels_to_system_info(DICTIONARY *labels) { + struct rrdhost_system_info *info = callocz(1, sizeof(struct rrdhost_system_info)); + info->hops = 1; + + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->cloud_provider_type, "_cloud_provider_type"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->cloud_instance_type, "_cloud_instance_type"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->cloud_instance_region, "_cloud_instance_region"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->host_os_name, "_os_name"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->host_os_version, "_os_version"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->kernel_version, "_kernel_version"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->host_cores, "_system_cores"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->host_cpu_freq, "_system_cpu_freq"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->host_ram_total, "_system_ram_total"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->host_disk_space, "_system_disk_space"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->architecture, "_architecture"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->virtualization, "_virtualization"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->container, "_container"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->container_detection, "_container_detection"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->virt_detection, "_virt_detection"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->is_k8s_node, "_is_k8s_node"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->install_type, "_install_type"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->prebuilt_arch, "_prebuilt_arch"); + rrdlabels_get_value_strdup_or_null(labels, &localhost->system_info->prebuilt_dist, "_prebuilt_dist"); + + return info; +} + static void rrdhost_load_auto_labels(void) { DICTIONARY *labels = localhost->rrdlabels; @@ -1289,8 +1316,7 @@ static void rrdhost_load_auto_labels(void) { rrdlabels_add(labels, "_cloud_instance_type", localhost->system_info->cloud_instance_type, RRDLABEL_SRC_AUTO); if (localhost->system_info->cloud_instance_region) - rrdlabels_add( - labels, "_cloud_instance_region", localhost->system_info->cloud_instance_region, RRDLABEL_SRC_AUTO); + rrdlabels_add(labels, "_cloud_instance_region", localhost->system_info->cloud_instance_region, RRDLABEL_SRC_AUTO); if (localhost->system_info->host_os_name) rrdlabels_add(labels, "_os_name", localhost->system_info->host_os_name, RRDLABEL_SRC_AUTO); @@ -1354,8 +1380,7 @@ void rrdhost_set_is_parent_label(int count) { DICTIONARY *labels = localhost->rrdlabels; if (count == 0 || count == 1) { - rrdlabels_add( - labels, "_is_parent", (count) ? "true" : "false", RRDLABEL_SRC_AUTO); + rrdlabels_add(labels, "_is_parent", (count) ? "true" : "false", RRDLABEL_SRC_AUTO); //queue a node info #ifdef ENABLE_ACLK diff --git a/database/rrdlabels.c b/database/rrdlabels.c index 4a9a6dae6a..38ca9e6159 100644 --- a/database/rrdlabels.c +++ b/database/rrdlabels.c @@ -654,7 +654,7 @@ void rrdlabels_get_value_to_buffer_or_null(DICTIONARY *labels, BUFFER *wb, const // ---------------------------------------------------------------------------- // rrdlabels_get_value_to_char_or_null() -void rrdlabels_get_value_to_char_or_null(DICTIONARY *labels, char **value, const char *key) { +void rrdlabels_get_value_strdup_or_null(DICTIONARY *labels, char **value, const char *key) { const DICTIONARY_ITEM *acquired_item = dictionary_get_and_acquire_item(labels, key); RRDLABEL *lb = dictionary_acquired_item_value(acquired_item); |