RRDHOST system-info isolation (#19235)
* isolate struct system_info from the rest of netdata and provide an API to access it * make sure system_info is always consumed
Costa Tsaousis committed
Dec 17, 2024 at 13:04 UTC
f4b52dfa5ea844619b47b4e3566aa5e5421ff9e6
24 files changed
+714
-584
CMakeLists.txt
+2
@@ -1441,6 +1441,8 @@ set(RRD_PLUGIN_FILES
1441
src/database/rrd-database-mode.c
1442
src/database/rrdhost-state-id.c
1443
src/database/rrdhost-state-id.h
1444
+ src/database/rrdhost-system-info.c
1445
+ src/database/rrdhost-system-info.h
1446
)
1447
1448
if(ENABLE_DBENGINE)
src/aclk/aclk.c
+11
-6
@@ -858,7 +858,7 @@ void aclk_host_state_update(RRDHOST *host, int cmd, int queryable)
858
859
node_instance_creation_t node_instance_creation = {
860
.claim_id = claim_id_is_set(claim_id) ? claim_id.str : NULL,
861
- .hops = host->system_info->hops,
861
+ .hops = rrdhost_system_info_hops(host->system_info),
862
.hostname = rrdhost_hostname(host),
863
.machine_guid = host->machine_guid};
864
@@ -868,7 +868,8 @@ void aclk_host_state_update(RRDHOST *host, int cmd, int queryable)
868
create_query->data.bin_payload.topic = ACLK_TOPICID_CREATE_NODE;
869
create_query->data.bin_payload.msg_name = "CreateNodeInstance";
870
nd_log(NDLS_DAEMON, NDLP_DEBUG,
871
- "Registering host=%s, hops=%d", host->machine_guid, host->system_info->hops);
871
+ "Registering host=%s, hops=%d", host->machine_guid,
872
+ rrdhost_system_info_hops(host->system_info));
873
874
aclk_execute_query(create_query);
875
return;
@@ -877,7 +878,7 @@ void aclk_host_state_update(RRDHOST *host, int cmd, int queryable)
878
879
aclk_query_t query = aclk_query_new(NODE_STATE_UPDATE);
880
node_instance_connection_t node_state_update = {
880
- .hops = host->system_info->hops,
881
+ .hops = rrdhost_system_info_hops(host->system_info),
882
.live = cmd,
883
.queryable = queryable,
884
.session_id = aclk_session_newarch
@@ -893,7 +894,9 @@ void aclk_host_state_update(RRDHOST *host, int cmd, int queryable)
894
895
nd_log(NDLS_DAEMON, NDLP_DEBUG,
896
"Queuing status update for node=%s, live=%d, hops=%d, queryable=%d",
896
- (char*)node_state_update.node_id, cmd, host->system_info->hops, queryable);
897
+ (char*)node_state_update.node_id, cmd,
898
+ rrdhost_system_info_hops(host->system_info), queryable);
899
+
900
freez((void*)node_state_update.node_id);
901
query->data.bin_payload.msg_name = "UpdateNodeInstanceConnection";
902
query->data.bin_payload.topic = ACLK_TOPICID_NODE_CONN;
@@ -1063,7 +1066,9 @@ char *aclk_state(void)
1066
buffer_sprintf(wb, "\n\tNode ID: %s\n", node_id_str);
1067
}
1068
1066
- buffer_sprintf(wb, "\tStreaming Hops: %d\n\tRelationship: %s", host->system_info->hops, host == localhost ? "self" : "child");
1069
+ buffer_sprintf(wb, "\tStreaming Hops: %d\n\tRelationship: %s",
1070
+ rrdhost_system_info_hops(host->system_info),
1071
+ host == localhost ? "self" : "child");
1072
1073
if (host != localhost)
1074
buffer_sprintf(wb, "\n\tStreaming Connection Live: %s", host->receiver ? "true" : "false");
@@ -1197,7 +1202,7 @@ char *aclk_state_json(void)
1202
json_object_object_add(nodeinstance, "node-id", tmp);
1203
}
1204
1200
- tmp = json_object_new_int(host->system_info->hops);
1205
+ tmp = json_object_new_int(rrdhost_system_info_hops(host->system_info));
1206
json_object_object_add(nodeinstance, "streaming-hops", tmp);
1207
1208
tmp = json_object_new_string(host == localhost ? "self" : "child");
src/aclk/aclk_rx_msgs.c
+1
-1
@@ -286,7 +286,7 @@ int create_node_instance_result(const char *msg, size_t msg_len)
286
node_state_update.hops = 0;
287
} else {
288
node_state_update.live = (!rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN));
289
- node_state_update.hops = host->system_info->hops;
289
+ node_state_update.hops = rrdhost_system_info_hops(host->system_info);
290
}
291
node_state_update.capabilities = aclk_get_node_instance_capas(host);
292
}
src/daemon/analytics.c
+9
-10
@@ -356,17 +356,16 @@ void analytics_alarms_notifications(void)
356
buffer_free(b);
357
}
358
359
-static void analytics_get_install_type(struct rrdhost_system_info *system_info)
360
-{
361
- if (system_info->install_type == NULL) {
362
- analytics_set_data_str(&analytics_data.netdata_install_type, "unknown");
363
- } else {
364
- analytics_set_data_str(&analytics_data.netdata_install_type, system_info->install_type);
365
- }
359
+static void analytics_get_install_type(struct rrdhost_system_info *system_info) {
360
+ const char *install_type = rrdhost_system_info_install_type(system_info);
361
+ if(!install_type)
362
+ install_type = "unknown";
363
367
- if (system_info->prebuilt_dist != NULL) {
368
- analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, system_info->prebuilt_dist);
369
- }
364
+ analytics_set_data_str(&analytics_data.netdata_install_type, install_type);
365
+
366
+ const char *prebuilt_dist = rrdhost_system_info_prebuilt_dist(system_info);
367
+ if(prebuilt_dist)
368
+ analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, prebuilt_dist);
369
}
370
371
/*
src/daemon/analytics.h
+1
-1
@@ -4,6 +4,7 @@
4
#define NETDATA_ANALYTICS_H 1
5
6
#include "daemon/common.h"
7
+#include "database/rrdhost-system-info.h"
8
9
/* Max number of seconds before the first META analytics is sent */
10
#define ANALYTICS_INIT_SLEEP_SEC 120
@@ -76,7 +77,6 @@ struct analytics_data {
77
bool exporting_enabled;
78
};
79
79
-struct rrdhost_system_info;
80
void set_late_analytics_variables(struct rrdhost_system_info *system_info);
81
void analytics_free_data(void);
82
void analytics_log_shell(void);
src/daemon/buildinfo.c
+10
-6
@@ -1,5 +1,6 @@
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
+#define RRDHOST_SYSTEM_INFO_INTERNALS
4
#include <stdio.h>
5
#include "./config.h"
6
#include "common.h"
@@ -1260,7 +1261,6 @@ __attribute__((constructor)) void initialize_build_info(void) {
1261
// ----------------------------------------------------------------------------
1262
// system info
1263
1263
-int get_system_info(struct rrdhost_system_info *system_info);
1264
static void populate_system_info(void) {
1265
static bool populated = false;
1266
static SPINLOCK spinlock = SPINLOCK_INITIALIZER;
@@ -1288,8 +1288,8 @@ static void populate_system_info(void) {
1288
netdata_main_spawn_server_init(NULL, 0, NULL);
1289
}
1290
1291
- system_info = callocz(1, sizeof(struct rrdhost_system_info));
1292
- get_system_info(system_info);
1291
+ system_info = rrdhost_system_info_create();
1292
+ rrdhost_system_info_detect(system_info);
1293
free_system_info = true;
1294
1295
if(started_spawn_server)
@@ -1349,11 +1349,11 @@ char *get_value_from_key(char *buffer, char *key) {
1349
return s;
1350
}
1351
1352
-void get_install_type(char **install_type, char **prebuilt_arch __maybe_unused, char **prebuilt_dist __maybe_unused) {
1352
+void get_install_type_internal(char **install_type, char **prebuilt_arch __maybe_unused, char **prebuilt_dist __maybe_unused) {
1353
#ifndef OS_WINDOWS
1354
char *install_type_filename;
1355
1356
- int install_type_filename_len = (strlen(netdata_configured_user_config_dir) + strlen(".install-type") + 3);
1356
+ unsigned long install_type_filename_len = (strlen(netdata_configured_user_config_dir) + strlen(".install-type") + 3);
1357
install_type_filename = mallocz(sizeof(char) * install_type_filename_len);
1358
snprintfz(install_type_filename, install_type_filename_len - 1, "%s/%s", netdata_configured_user_config_dir, ".install-type");
1359
@@ -1378,6 +1378,10 @@ void get_install_type(char **install_type, char **prebuilt_arch __maybe_unused,
1378
#endif
1379
}
1380
1381
+void get_install_type(struct rrdhost_system_info *system_info) {
1382
+ get_install_type_internal(&system_info->install_type, &system_info->prebuilt_arch, &system_info->prebuilt_dist);
1383
+}
1384
+
1385
static struct {
1386
SPINLOCK spinlock;
1387
bool populated;
@@ -1392,7 +1396,7 @@ static void populate_packaging_info() {
1396
if(!BUILD_PACKAGING_INFO.populated) {
1397
BUILD_PACKAGING_INFO.populated = true;
1398
1395
- get_install_type(&BUILD_PACKAGING_INFO.install_type, &BUILD_PACKAGING_INFO.prebuilt_arch, &BUILD_PACKAGING_INFO.prebuilt_distro);
1399
+ get_install_type_internal(&BUILD_PACKAGING_INFO.install_type, &BUILD_PACKAGING_INFO.prebuilt_arch, &BUILD_PACKAGING_INFO.prebuilt_distro);
1400
1401
if(!BUILD_PACKAGING_INFO.install_type)
1402
BUILD_PACKAGING_INFO.install_type = "unknown";
src/daemon/buildinfo.h
+1
-1
@@ -9,7 +9,7 @@ void print_build_info_json(void);
9
10
char *get_value_from_key(char *buffer, char *key);
11
12
-void get_install_type(char **install_type, char **prebuilt_arch, char **prebuilt_dist);
12
+void get_install_type(struct rrdhost_system_info *system_info);
13
14
void build_info_to_json_object(BUFFER *b);
15
src/daemon/main.c
+3
-55
@@ -179,56 +179,6 @@ int help(int exitcode) {
179
return exitcode;
180
}
181
182
-// coverity[ +tainted_string_sanitize_content : arg-0 ]
183
-static inline void coverity_remove_taint(char *s)
184
-{
185
- (void)s;
186
-}
187
-
188
-int get_system_info(struct rrdhost_system_info *system_info) {
189
-#if !defined(OS_WINDOWS)
190
- char *script;
191
- script = mallocz(sizeof(char) * (strlen(netdata_configured_primary_plugins_dir) + strlen("system-info.sh") + 2));
192
- sprintf(script, "%s/%s", netdata_configured_primary_plugins_dir, "system-info.sh");
193
- if (unlikely(access(script, R_OK) != 0)) {
194
- netdata_log_error("System info script %s not found.",script);
195
- freez(script);
196
- return 1;
197
- }
198
-
199
- POPEN_INSTANCE *instance = spawn_popen_run(script);
200
- if(instance) {
201
- char line[200 + 1];
202
- // Removed the double strlens, if the Coverity tainted string warning reappears I'll revert.
203
- // One time init code, but I'm curious about the warning...
204
- while (fgets(line, 200, spawn_popen_stdout(instance)) != NULL) {
205
- char *value=line;
206
- while (*value && *value != '=') value++;
207
- if (*value=='=') {
208
- *value='\0';
209
- value++;
210
- char *end = value;
211
- while (*end && *end != '\n') end++;
212
- *end = '\0'; // Overwrite newline if present
213
- coverity_remove_taint(line); // I/O is controlled result of system_info.sh - not tainted
214
- coverity_remove_taint(value);
215
-
216
- if(unlikely(rrdhost_set_system_info_variable(system_info, line, value))) {
217
- netdata_log_error("Unexpected environment variable %s=%s", line, value);
218
- } else {
219
- nd_setenv(line, value, 1);
220
- }
221
- }
222
- }
223
- spawn_popen_wait(instance);
224
- }
225
- freez(script);
226
-#else
227
- netdata_windows_get_system_info(system_info);
228
-#endif
229
- return 0;
230
-}
231
-
182
/* Any config setting that can be accessed without a default value i.e. configget(...,...,NULL) *MUST*
183
be set in this procedure to be called in all the relevant code paths.
184
*/
@@ -963,9 +913,8 @@ int netdata_main(int argc, char **argv) {
913
delta_startup_time("collecting system info");
914
915
netdata_anonymous_statistics_enabled=-1;
966
- struct rrdhost_system_info *system_info = callocz(1, sizeof(struct rrdhost_system_info));
967
- __atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
968
- get_system_info(system_info);
916
+ struct rrdhost_system_info *system_info = rrdhost_system_info_create();
917
+ rrdhost_system_info_detect(system_info);
918
919
const char *guid = registry_get_this_machine_guid();
920
#ifdef ENABLE_SENTRY
@@ -974,8 +923,7 @@ int netdata_main(int argc, char **argv) {
923
UNUSED(guid);
924
#endif
925
977
- system_info->hops = 0;
978
- get_install_type(&system_info->install_type, &system_info->prebuilt_arch, &system_info->prebuilt_dist);
926
+ get_install_type(system_info);
927
928
delta_startup_time("initialize RRD structures");
929
src/database/contexts/api_v2_contexts.c
+1
-26
@@ -372,32 +372,7 @@ static void rrdcontext_to_json_v2_rrdhost(BUFFER *wb, RRDHOST *host, struct rrdc
372
buffer_json_member_add_string(wb, "v", rrdhost_program_version(host));
373
374
host_labels2json(host, wb, "labels");
375
-
376
- if (host->system_info) {
377
- buffer_json_member_add_object(wb, "hw");
378
- {
379
- buffer_json_member_add_string_or_empty(wb, "architecture", host->system_info->architecture);
380
- buffer_json_member_add_string_or_empty(wb, "cpu_frequency", host->system_info->host_cpu_freq);
381
- buffer_json_member_add_string_or_empty(wb, "cpus", host->system_info->host_cores);
382
- buffer_json_member_add_string_or_empty(wb, "memory", host->system_info->host_ram_total);
383
- buffer_json_member_add_string_or_empty(wb, "disk_space", host->system_info->host_disk_space);
384
- buffer_json_member_add_string_or_empty(wb, "virtualization", host->system_info->virtualization);
385
- buffer_json_member_add_string_or_empty(wb, "container", host->system_info->container);
386
- }
387
- buffer_json_object_close(wb);
388
-
389
- buffer_json_member_add_object(wb, "os");
390
- {
391
- buffer_json_member_add_string_or_empty(wb, "id", host->system_info->host_os_id);
392
- buffer_json_member_add_string_or_empty(wb, "nm", host->system_info->host_os_name);
393
- buffer_json_member_add_string_or_empty(wb, "v", host->system_info->host_os_version);
394
- buffer_json_member_add_object(wb, "kernel");
395
- buffer_json_member_add_string_or_empty(wb, "nm", host->system_info->kernel_name);
396
- buffer_json_member_add_string_or_empty(wb, "v", host->system_info->kernel_version);
397
- buffer_json_object_close(wb);
398
- }
399
- buffer_json_object_close(wb);
400
- }
375
+ rrdhost_system_info_to_json_v2(wb, host->system_info);
376
377
// created - the node is created but never connected to cloud
378
// unreachable - not currently connected
src/database/rrd.h
+1
-46
@@ -13,6 +13,7 @@ extern "C" {
13
#include "streaming/stream-sender-commit.h"
14
#include "rrdhost-state-id.h"
15
#include "health/health-alert-log.h"
16
+#include "rrdhost-system-info.h"
17
18
// non-existing structs instead of voids
19
// to enable type checking at compile time
@@ -27,8 +28,6 @@ typedef struct rrdset RRDSET;
28
typedef struct rrdcalc RRDCALC;
29
typedef struct alarm_entry ALARM_ENTRY;
30
30
-typedef struct rrdlabels RRDLABELS;
31
-
31
typedef struct rrdvar_acquired RRDVAR_ACQUIRED;
32
typedef struct rrdcalc_acquired RRDCALC_ACQUIRED;
33
@@ -1015,47 +1014,6 @@ typedef enum __attribute__ ((__packed__)) {
1014
// ----------------------------------------------------------------------------
1015
// RRD HOST
1016
1018
-struct rrdhost_system_info {
1019
- char *cloud_provider_type;
1020
- char *cloud_instance_type;
1021
- char *cloud_instance_region;
1022
-
1023
- char *host_os_name;
1024
- char *host_os_id;
1025
- char *host_os_id_like;
1026
- char *host_os_version;
1027
- char *host_os_version_id;
1028
- char *host_os_detection;
1029
- char *host_cores;
1030
- char *host_cpu_freq;
1031
- char *host_cpu_model;
1032
- char *host_ram_total;
1033
- char *host_disk_space;
1034
- char *container_os_name;
1035
- char *container_os_id;
1036
- char *container_os_id_like;
1037
- char *container_os_version;
1038
- char *container_os_version_id;
1039
- char *container_os_detection;
1040
- char *kernel_name;
1041
- char *kernel_version;
1042
- char *architecture;
1043
- char *virtualization;
1044
- char *virt_detection;
1045
- char *container;
1046
- char *container_detection;
1047
- char *is_k8s_node;
1048
- int16_t hops;
1049
- bool ml_capable;
1050
- bool ml_enabled;
1051
- char *install_type;
1052
- char *prebuilt_arch;
1053
- char *prebuilt_dist;
1054
- int mc_version;
1055
-};
1056
-
1057
-struct rrdhost_system_info *rrdhost_labels_to_system_info(RRDLABELS *labels);
1058
-
1017
struct stream_thread;
1018
1019
struct rrdhost {
@@ -1365,8 +1323,6 @@ RRDHOST *rrdhost_find_or_create(
1323
struct rrdhost_system_info *system_info,
1324
bool is_archived);
1325
1368
-int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value);
1369
-
1326
// ----------------------------------------------------------------------------
1327
// RRDSET functions
1328
@@ -1426,7 +1382,6 @@ RRDSET *rrdset_create_localhost(
1382
1383
void rrdhost_free_all(void);
1384
1429
-void rrdhost_system_info_free(struct rrdhost_system_info *system_info);
1385
void rrdhost_free___while_having_rrd_wrlock(RRDHOST *host, bool force);
1386
1387
bool rrdhost_should_be_removed(RRDHOST *host, RRDHOST *protected_host, time_t now_s);
src/database/rrdfunctions.c
+1
-1
@@ -296,7 +296,7 @@ int rrd_functions_find_by_name(RRDHOST *host, BUFFER *wb, const char *name, size
296
rrd_collector_running(rdcf->collector) ? "yes" : "no",
297
host->stream.rcv.status.tid, host->stream.snd.status.tid,
298
state_id, rdcf->rrdhost_state_id,
299
- host->system_info->hops
299
+ rrdhost_system_info_hops(host->system_info)
300
);
301
302
dictionary_acquired_item_release(host->functions, *item);
src/database/rrdhost-system-info.c
new
+499
@@ -0,0 +1,499 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#define RRDHOST_SYSTEM_INFO_INTERNALS
4
+#include "rrdhost-system-info.h"
5
+#include "daemon/common.h"
6
+#include "aclk/schema-wrappers/node_info.h"
7
+
8
+// coverity[ +tainted_string_sanitize_content : arg-0 ]
9
+static inline void coverity_remove_taint(char *s __maybe_unused) { }
10
+
11
+// ----------------------------------------------------------------------------
12
+// RRDHOST - set system info from environment variables
13
+// system_info fields must be heap allocated or NULL
14
+int rrdhost_system_info_set_by_name(struct rrdhost_system_info *system_info, char *name, char *value) {
15
+ int res = 0;
16
+
17
+ if (!strcmp(name, "NETDATA_PROTOCOL_VERSION"))
18
+ return res;
19
+
20
+ else if(!strcmp(name, "NETDATA_INSTANCE_CLOUD_TYPE")){
21
+ freez(system_info->cloud_provider_type);
22
+ system_info->cloud_provider_type = strdupz(value);
23
+ }
24
+ else if(!strcmp(name, "NETDATA_INSTANCE_CLOUD_INSTANCE_TYPE")){
25
+ freez(system_info->cloud_instance_type);
26
+ system_info->cloud_instance_type = strdupz(value);
27
+ }
28
+ else if(!strcmp(name, "NETDATA_INSTANCE_CLOUD_INSTANCE_REGION")){
29
+ freez(system_info->cloud_instance_region);
30
+ system_info->cloud_instance_region = strdupz(value);
31
+ }
32
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_NAME")){
33
+ freez(system_info->container_os_name);
34
+ system_info->container_os_name = strdupz(value);
35
+ }
36
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_ID")){
37
+ freez(system_info->container_os_id);
38
+ system_info->container_os_id = strdupz(value);
39
+ }
40
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_ID_LIKE")){
41
+ freez(system_info->container_os_id_like);
42
+ system_info->container_os_id_like = strdupz(value);
43
+ }
44
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_VERSION")){
45
+ freez(system_info->container_os_version);
46
+ system_info->container_os_version = strdupz(value);
47
+ }
48
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_VERSION_ID")){
49
+ freez(system_info->container_os_version_id);
50
+ system_info->container_os_version_id = strdupz(value);
51
+ }
52
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_DETECTION")){
53
+ freez(system_info->container_os_detection);
54
+ system_info->container_os_detection = strdupz(value);
55
+ }
56
+ else if(!strcmp(name, "NETDATA_HOST_OS_NAME")){
57
+ freez(system_info->host_os_name);
58
+ system_info->host_os_name = strdupz(value);
59
+ json_fix_string(system_info->host_os_name);
60
+ }
61
+ else if(!strcmp(name, "NETDATA_HOST_OS_ID")){
62
+ freez(system_info->host_os_id);
63
+ system_info->host_os_id = strdupz(value);
64
+ }
65
+ else if(!strcmp(name, "NETDATA_HOST_OS_ID_LIKE")){
66
+ freez(system_info->host_os_id_like);
67
+ system_info->host_os_id_like = strdupz(value);
68
+ }
69
+ else if(!strcmp(name, "NETDATA_HOST_OS_VERSION")){
70
+ freez(system_info->host_os_version);
71
+ system_info->host_os_version = strdupz(value);
72
+ }
73
+ else if(!strcmp(name, "NETDATA_HOST_OS_VERSION_ID")){
74
+ freez(system_info->host_os_version_id);
75
+ system_info->host_os_version_id = strdupz(value);
76
+ }
77
+ else if(!strcmp(name, "NETDATA_HOST_OS_DETECTION")){
78
+ freez(system_info->host_os_detection);
79
+ system_info->host_os_detection = strdupz(value);
80
+ }
81
+ else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_NAME")){
82
+ freez(system_info->kernel_name);
83
+ system_info->kernel_name = strdupz(value);
84
+ }
85
+ else if(!strcmp(name, "NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT")){
86
+ freez(system_info->host_cores);
87
+ system_info->host_cores = strdupz(value);
88
+ }
89
+ else if(!strcmp(name, "NETDATA_SYSTEM_CPU_FREQ")){
90
+ freez(system_info->host_cpu_freq);
91
+ system_info->host_cpu_freq = strdupz(value);
92
+ }
93
+ else if (!strcmp(name, "NETDATA_SYSTEM_CPU_MODEL")){
94
+ freez(system_info->host_cpu_model);
95
+ system_info->host_cpu_model = strdupz(value);
96
+ }
97
+ else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_RAM")){
98
+ freez(system_info->host_ram_total);
99
+ system_info->host_ram_total = strdupz(value);
100
+ }
101
+ else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_DISK_SIZE")){
102
+ freez(system_info->host_disk_space);
103
+ system_info->host_disk_space = strdupz(value);
104
+ }
105
+ else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_VERSION")){
106
+ freez(system_info->kernel_version);
107
+ system_info->kernel_version = strdupz(value);
108
+ }
109
+ else if(!strcmp(name, "NETDATA_SYSTEM_ARCHITECTURE")){
110
+ freez(system_info->architecture);
111
+ system_info->architecture = strdupz(value);
112
+ }
113
+ else if(!strcmp(name, "NETDATA_SYSTEM_VIRTUALIZATION")){
114
+ freez(system_info->virtualization);
115
+ system_info->virtualization = strdupz(value);
116
+ }
117
+ else if(!strcmp(name, "NETDATA_SYSTEM_VIRT_DETECTION")){
118
+ freez(system_info->virt_detection);
119
+ system_info->virt_detection = strdupz(value);
120
+ }
121
+ else if(!strcmp(name, "NETDATA_SYSTEM_CONTAINER")){
122
+ freez(system_info->container);
123
+ system_info->container = strdupz(value);
124
+ }
125
+ else if(!strcmp(name, "NETDATA_SYSTEM_CONTAINER_DETECTION")){
126
+ freez(system_info->container_detection);
127
+ system_info->container_detection = strdupz(value);
128
+ }
129
+ else if(!strcmp(name, "NETDATA_HOST_IS_K8S_NODE")){
130
+ freez(system_info->is_k8s_node);
131
+ system_info->is_k8s_node = strdupz(value);
132
+ }
133
+ else if (!strcmp(name, "NETDATA_SYSTEM_CPU_VENDOR"))
134
+ return res;
135
+ else if (!strcmp(name, "NETDATA_SYSTEM_CPU_DETECTION"))
136
+ return res;
137
+ else if (!strcmp(name, "NETDATA_SYSTEM_RAM_DETECTION"))
138
+ return res;
139
+ else if (!strcmp(name, "NETDATA_SYSTEM_DISK_DETECTION"))
140
+ return res;
141
+ else if (!strcmp(name, "NETDATA_CONTAINER_IS_OFFICIAL_IMAGE"))
142
+ return res;
143
+ else {
144
+ res = 1;
145
+ }
146
+
147
+ return res;
148
+}
149
+
150
+struct rrdhost_system_info *rrdhost_system_info_from_host_labels(RRDLABELS *labels) {
151
+ struct rrdhost_system_info *info = rrdhost_system_info_create();
152
+ info->hops = 1;
153
+
154
+ rrdlabels_get_value_strdup_or_null(labels, &info->cloud_provider_type, "_cloud_provider_type");
155
+ rrdlabels_get_value_strdup_or_null(labels, &info->cloud_instance_type, "_cloud_instance_type");
156
+ rrdlabels_get_value_strdup_or_null(labels, &info->cloud_instance_region, "_cloud_instance_region");
157
+ rrdlabels_get_value_strdup_or_null(labels, &info->host_os_name, "_os_name");
158
+ rrdlabels_get_value_strdup_or_null(labels, &info->host_os_version, "_os_version");
159
+ rrdlabels_get_value_strdup_or_null(labels, &info->kernel_version, "_kernel_version");
160
+ rrdlabels_get_value_strdup_or_null(labels, &info->host_cores, "_system_cores");
161
+ rrdlabels_get_value_strdup_or_null(labels, &info->host_cpu_freq, "_system_cpu_freq");
162
+ rrdlabels_get_value_strdup_or_null(labels, &info->host_cpu_model, "_system_cpu_model");
163
+ rrdlabels_get_value_strdup_or_null(labels, &info->host_ram_total, "_system_ram_total");
164
+ rrdlabels_get_value_strdup_or_null(labels, &info->host_disk_space, "_system_disk_space");
165
+ rrdlabels_get_value_strdup_or_null(labels, &info->architecture, "_architecture");
166
+ rrdlabels_get_value_strdup_or_null(labels, &info->virtualization, "_virtualization");
167
+ rrdlabels_get_value_strdup_or_null(labels, &info->container, "_container");
168
+ rrdlabels_get_value_strdup_or_null(labels, &info->container_detection, "_container_detection");
169
+ rrdlabels_get_value_strdup_or_null(labels, &info->virt_detection, "_virt_detection");
170
+ rrdlabels_get_value_strdup_or_null(labels, &info->is_k8s_node, "_is_k8s_node");
171
+ rrdlabels_get_value_strdup_or_null(labels, &info->install_type, "_install_type");
172
+ rrdlabels_get_value_strdup_or_null(labels, &info->prebuilt_arch, "_prebuilt_arch");
173
+ rrdlabels_get_value_strdup_or_null(labels, &info->prebuilt_dist, "_prebuilt_dist");
174
+
175
+ return info;
176
+}
177
+
178
+void rrdhost_system_info_to_rrdlabels(struct rrdhost_system_info *system_info, RRDLABELS *labels) {
179
+ if (system_info->cloud_provider_type)
180
+ rrdlabels_add(labels, "_cloud_provider_type", system_info->cloud_provider_type, RRDLABEL_SRC_AUTO);
181
+
182
+ if (system_info->cloud_instance_type)
183
+ rrdlabels_add(labels, "_cloud_instance_type", system_info->cloud_instance_type, RRDLABEL_SRC_AUTO);
184
+
185
+ if (system_info->cloud_instance_region)
186
+ rrdlabels_add(labels, "_cloud_instance_region", system_info->cloud_instance_region, RRDLABEL_SRC_AUTO);
187
+
188
+ if (system_info->host_os_name)
189
+ rrdlabels_add(labels, "_os_name", system_info->host_os_name, RRDLABEL_SRC_AUTO);
190
+
191
+ if (system_info->host_os_version)
192
+ rrdlabels_add(labels, "_os_version", system_info->host_os_version, RRDLABEL_SRC_AUTO);
193
+
194
+ if (system_info->kernel_version)
195
+ rrdlabels_add(labels, "_kernel_version", system_info->kernel_version, RRDLABEL_SRC_AUTO);
196
+
197
+ if (system_info->host_cores)
198
+ rrdlabels_add(labels, "_system_cores", system_info->host_cores, RRDLABEL_SRC_AUTO);
199
+
200
+ if (system_info->host_cpu_freq)
201
+ rrdlabels_add(labels, "_system_cpu_freq", system_info->host_cpu_freq, RRDLABEL_SRC_AUTO);
202
+
203
+ if (system_info->host_cpu_model)
204
+ rrdlabels_add(labels, "_system_cpu_model", system_info->host_cpu_model, RRDLABEL_SRC_AUTO);
205
+
206
+ if (system_info->host_ram_total)
207
+ rrdlabels_add(labels, "_system_ram_total", system_info->host_ram_total, RRDLABEL_SRC_AUTO);
208
+
209
+ if (system_info->host_disk_space)
210
+ rrdlabels_add(labels, "_system_disk_space", system_info->host_disk_space, RRDLABEL_SRC_AUTO);
211
+
212
+ if (system_info->architecture)
213
+ rrdlabels_add(labels, "_architecture", system_info->architecture, RRDLABEL_SRC_AUTO);
214
+
215
+ if (system_info->virtualization)
216
+ rrdlabels_add(labels, "_virtualization", system_info->virtualization, RRDLABEL_SRC_AUTO);
217
+
218
+ if (system_info->container)
219
+ rrdlabels_add(labels, "_container", system_info->container, RRDLABEL_SRC_AUTO);
220
+
221
+ if (system_info->container_detection)
222
+ rrdlabels_add(labels, "_container_detection", system_info->container_detection, RRDLABEL_SRC_AUTO);
223
+
224
+ if (system_info->virt_detection)
225
+ rrdlabels_add(labels, "_virt_detection", system_info->virt_detection, RRDLABEL_SRC_AUTO);
226
+
227
+ if (system_info->is_k8s_node)
228
+ rrdlabels_add(labels, "_is_k8s_node", system_info->is_k8s_node, RRDLABEL_SRC_AUTO);
229
+
230
+ if (system_info->install_type)
231
+ rrdlabels_add(labels, "_install_type", system_info->install_type, RRDLABEL_SRC_AUTO);
232
+
233
+ if (system_info->prebuilt_arch)
234
+ rrdlabels_add(labels, "_prebuilt_arch", system_info->prebuilt_arch, RRDLABEL_SRC_AUTO);
235
+
236
+ if (system_info->prebuilt_dist)
237
+ rrdlabels_add(labels, "_prebuilt_dist", system_info->prebuilt_dist, RRDLABEL_SRC_AUTO);
238
+}
239
+
240
+int rrdhost_system_info_detect(struct rrdhost_system_info *system_info) {
241
+#if !defined(OS_WINDOWS)
242
+ char *script;
243
+ script = mallocz(sizeof(char) * (strlen(netdata_configured_primary_plugins_dir) + strlen("system-info.sh") + 2));
244
+ sprintf(script, "%s/%s", netdata_configured_primary_plugins_dir, "system-info.sh");
245
+ if (unlikely(access(script, R_OK) != 0)) {
246
+ netdata_log_error("System info script %s not found.",script);
247
+ freez(script);
248
+ return 1;
249
+ }
250
+
251
+ POPEN_INSTANCE *instance = spawn_popen_run(script);
252
+ if(instance) {
253
+ char line[200 + 1];
254
+ // Removed the double strlens, if the Coverity tainted string warning reappears I'll revert.
255
+ // One time init code, but I'm curious about the warning...
256
+ while (fgets(line, 200, spawn_popen_stdout(instance)) != NULL) {
257
+ char *value=line;
258
+ while (*value && *value != '=') value++;
259
+ if (*value=='=') {
260
+ *value='\0';
261
+ value++;
262
+ char *end = value;
263
+ while (*end && *end != '\n') end++;
264
+ *end = '\0'; // Overwrite newline if present
265
+ coverity_remove_taint(line); // I/O is controlled result of system_info.sh - not tainted
266
+ coverity_remove_taint(value);
267
+
268
+ if(unlikely(rrdhost_system_info_set_by_name(system_info, line, value))) {
269
+ netdata_log_error("Unexpected environment variable %s=%s", line, value);
270
+ } else {
271
+ nd_setenv(line, value, 1);
272
+ }
273
+ }
274
+ }
275
+ spawn_popen_wait(instance);
276
+ }
277
+ freez(script);
278
+#else
279
+ netdata_windows_get_system_info(system_info);
280
+#endif
281
+ return 0;
282
+}
283
+
284
+void rrdhost_system_info_free(struct rrdhost_system_info *system_info) {
285
+ if(likely(system_info)) {
286
+ __atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
287
+
288
+ freez(system_info->cloud_provider_type);
289
+ freez(system_info->cloud_instance_type);
290
+ freez(system_info->cloud_instance_region);
291
+ freez(system_info->host_os_name);
292
+ freez(system_info->host_os_id);
293
+ freez(system_info->host_os_id_like);
294
+ freez(system_info->host_os_version);
295
+ freez(system_info->host_os_version_id);
296
+ freez(system_info->host_os_detection);
297
+ freez(system_info->host_cores);
298
+ freez(system_info->host_cpu_freq);
299
+ freez(system_info->host_cpu_model);
300
+ freez(system_info->host_ram_total);
301
+ freez(system_info->host_disk_space);
302
+ freez(system_info->container_os_name);
303
+ freez(system_info->container_os_id);
304
+ freez(system_info->container_os_id_like);
305
+ freez(system_info->container_os_version);
306
+ freez(system_info->container_os_version_id);
307
+ freez(system_info->container_os_detection);
308
+ freez(system_info->kernel_name);
309
+ freez(system_info->kernel_version);
310
+ freez(system_info->architecture);
311
+ freez(system_info->virtualization);
312
+ freez(system_info->virt_detection);
313
+ freez(system_info->container);
314
+ freez(system_info->container_detection);
315
+ freez(system_info->is_k8s_node);
316
+ freez(system_info->install_type);
317
+ freez(system_info->prebuilt_arch);
318
+ freez(system_info->prebuilt_dist);
319
+ freez(system_info);
320
+ }
321
+}
322
+
323
+struct rrdhost_system_info *rrdhost_system_info_create(void) {
324
+ struct rrdhost_system_info *system_info = callocz(1, sizeof(struct rrdhost_system_info));
325
+ __atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
326
+ return system_info;
327
+}
328
+
329
+const char *rrdhost_system_info_install_type(struct rrdhost_system_info *si) {
330
+ return si->install_type;
331
+}
332
+
333
+const char *rrdhost_system_info_prebuilt_dist(struct rrdhost_system_info *si) {
334
+ return si->prebuilt_dist;
335
+}
336
+
337
+int16_t rrdhost_system_info_hops(struct rrdhost_system_info *si) {
338
+ if(!si) return 0;
339
+ return si->hops;
340
+}
341
+
342
+void rrdhost_system_info_hops_set(struct rrdhost_system_info *si, int16_t hops) {
343
+ si->hops = hops;
344
+}
345
+
346
+void rrdhost_system_info_to_json_v1(BUFFER *wb, struct rrdhost_system_info *system_info) {
347
+ if(!system_info) return;
348
+
349
+ buffer_json_member_add_string_or_empty(wb, "os_name", system_info->host_os_name);
350
+ buffer_json_member_add_string_or_empty(wb, "os_id", system_info->host_os_id);
351
+ buffer_json_member_add_string_or_empty(wb, "os_id_like", system_info->host_os_id_like);
352
+ buffer_json_member_add_string_or_empty(wb, "os_version", system_info->host_os_version);
353
+ buffer_json_member_add_string_or_empty(wb, "os_version_id", system_info->host_os_version_id);
354
+ buffer_json_member_add_string_or_empty(wb, "os_detection", system_info->host_os_detection);
355
+ buffer_json_member_add_string_or_empty(wb, "cores_total", system_info->host_cores);
356
+ buffer_json_member_add_string_or_empty(wb, "total_disk_space", system_info->host_disk_space);
357
+ buffer_json_member_add_string_or_empty(wb, "cpu_freq", system_info->host_cpu_freq);
358
+ buffer_json_member_add_string_or_empty(wb, "ram_total", system_info->host_ram_total);
359
+
360
+ buffer_json_member_add_string_or_omit(wb, "container_os_name", system_info->container_os_name);
361
+ buffer_json_member_add_string_or_omit(wb, "container_os_id", system_info->container_os_id);
362
+ buffer_json_member_add_string_or_omit(wb, "container_os_id_like", system_info->container_os_id_like);
363
+ buffer_json_member_add_string_or_omit(wb, "container_os_version", system_info->container_os_version);
364
+ buffer_json_member_add_string_or_omit(wb, "container_os_version_id", system_info->container_os_version_id);
365
+ buffer_json_member_add_string_or_omit(wb, "container_os_detection", system_info->container_os_detection);
366
+ buffer_json_member_add_string_or_omit(wb, "is_k8s_node", system_info->is_k8s_node);
367
+
368
+ buffer_json_member_add_string_or_empty(wb, "kernel_name", system_info->kernel_name);
369
+ buffer_json_member_add_string_or_empty(wb, "kernel_version", system_info->kernel_version);
370
+ buffer_json_member_add_string_or_empty(wb, "architecture", system_info->architecture);
371
+ buffer_json_member_add_string_or_empty(wb, "virtualization", system_info->virtualization);
372
+ buffer_json_member_add_string_or_empty(wb, "virt_detection", system_info->virt_detection);
373
+ buffer_json_member_add_string_or_empty(wb, "container", system_info->container);
374
+ buffer_json_member_add_string_or_empty(wb, "container_detection", system_info->container_detection);
375
+
376
+ buffer_json_member_add_string_or_omit(wb, "cloud_provider_type", system_info->cloud_provider_type);
377
+ buffer_json_member_add_string_or_omit(wb, "cloud_instance_type", system_info->cloud_instance_type);
378
+ buffer_json_member_add_string_or_omit(wb, "cloud_instance_region", system_info->cloud_instance_region);
379
+}
380
+
381
+void rrdhost_system_info_to_json_v2(BUFFER *wb, struct rrdhost_system_info *system_info) {
382
+ if(!system_info) return;
383
+
384
+ buffer_json_member_add_object(wb, "hw");
385
+ {
386
+ buffer_json_member_add_string_or_empty(wb, "architecture", system_info->architecture);
387
+ buffer_json_member_add_string_or_empty(wb, "cpu_frequency", system_info->host_cpu_freq);
388
+ buffer_json_member_add_string_or_empty(wb, "cpus", system_info->host_cores);
389
+ buffer_json_member_add_string_or_empty(wb, "memory", system_info->host_ram_total);
390
+ buffer_json_member_add_string_or_empty(wb, "disk_space", system_info->host_disk_space);
391
+ buffer_json_member_add_string_or_empty(wb, "virtualization", system_info->virtualization);
392
+ buffer_json_member_add_string_or_empty(wb, "container", system_info->container);
393
+ }
394
+ buffer_json_object_close(wb);
395
+
396
+ buffer_json_member_add_object(wb, "os");
397
+ {
398
+ buffer_json_member_add_string_or_empty(wb, "id", system_info->host_os_id);
399
+ buffer_json_member_add_string_or_empty(wb, "nm", system_info->host_os_name);
400
+ buffer_json_member_add_string_or_empty(wb, "v", system_info->host_os_version);
401
+ buffer_json_member_add_object(wb, "kernel");
402
+ buffer_json_member_add_string_or_empty(wb, "nm", system_info->kernel_name);
403
+ buffer_json_member_add_string_or_empty(wb, "v", system_info->kernel_version);
404
+ buffer_json_object_close(wb);
405
+ }
406
+ buffer_json_object_close(wb);
407
+}
408
+
409
+void rrdhost_system_info_ml_capable_set(struct rrdhost_system_info *system_info, bool capable) {
410
+ system_info->ml_capable = capable;
411
+}
412
+
413
+void rrdhost_system_info_ml_enabled_set(struct rrdhost_system_info *system_info, bool enabled) {
414
+ system_info->ml_enabled = enabled;
415
+}
416
+
417
+void rrdhost_system_info_mc_version_set(struct rrdhost_system_info *system_info, int version) {
418
+ system_info->mc_version = version;
419
+}
420
+
421
+int rrdhost_system_info_foreach(struct rrdhost_system_info *system_info, add_host_sysinfo_key_value_t cb, nd_uuid_t *uuid) {
422
+ int ret = 0;
423
+
424
+ ret += cb("NETDATA_CONTAINER_OS_NAME", system_info->container_os_name, uuid);
425
+ ret += cb("NETDATA_CONTAINER_OS_ID", system_info->container_os_id, uuid);
426
+ ret += cb("NETDATA_CONTAINER_OS_ID_LIKE", system_info->container_os_id_like, uuid);
427
+ ret += cb("NETDATA_CONTAINER_OS_VERSION", system_info->container_os_version, uuid);
428
+ ret += cb("NETDATA_CONTAINER_OS_VERSION_ID", system_info->container_os_version_id, uuid);
429
+ ret += cb("NETDATA_CONTAINER_OS_DETECTION", system_info->host_os_detection, uuid);
430
+ ret += cb("NETDATA_HOST_OS_NAME", system_info->host_os_name, uuid);
431
+ ret += cb("NETDATA_HOST_OS_ID", system_info->host_os_id, uuid);
432
+ ret += cb("NETDATA_HOST_OS_ID_LIKE", system_info->host_os_id_like, uuid);
433
+ ret += cb("NETDATA_HOST_OS_VERSION", system_info->host_os_version, uuid);
434
+ ret += cb("NETDATA_HOST_OS_VERSION_ID", system_info->host_os_version_id, uuid);
435
+ ret += cb("NETDATA_HOST_OS_DETECTION", system_info->host_os_detection, uuid);
436
+ ret += cb("NETDATA_SYSTEM_KERNEL_NAME", system_info->kernel_name, uuid);
437
+ ret += cb("NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT", system_info->host_cores, uuid);
438
+ ret += cb("NETDATA_SYSTEM_CPU_FREQ", system_info->host_cpu_freq, uuid);
439
+ ret += cb("NETDATA_SYSTEM_TOTAL_RAM", system_info->host_ram_total, uuid);
440
+ ret += cb("NETDATA_SYSTEM_TOTAL_DISK_SIZE", system_info->host_disk_space, uuid);
441
+ ret += cb("NETDATA_SYSTEM_KERNEL_VERSION", system_info->kernel_version, uuid);
442
+ ret += cb("NETDATA_SYSTEM_ARCHITECTURE", system_info->architecture, uuid);
443
+ ret += cb("NETDATA_SYSTEM_VIRTUALIZATION", system_info->virtualization, uuid);
444
+ ret += cb("NETDATA_SYSTEM_VIRT_DETECTION", system_info->virt_detection, uuid);
445
+ ret += cb("NETDATA_SYSTEM_CONTAINER", system_info->container, uuid);
446
+ ret += cb("NETDATA_SYSTEM_CONTAINER_DETECTION", system_info->container_detection, uuid);
447
+ ret += cb("NETDATA_HOST_IS_K8S_NODE", system_info->is_k8s_node, uuid);
448
+
449
+ return ret;
450
+}
451
+
452
+void rrdhost_system_info_to_url_encode_stream(BUFFER *wb, struct rrdhost_system_info *system_info) {
453
+ buffer_sprintf(wb, "&ml_capable=%d", system_info->ml_capable ? 1 : 0);
454
+ buffer_sprintf(wb, "&ml_enabled=%d", system_info->ml_enabled ? 1 : 0);
455
+ buffer_sprintf(wb, "&mc_version=%d", system_info->mc_version);
456
+ buffer_key_value_urlencode(wb, "&NETDATA_INSTANCE_CLOUD_TYPE", system_info->cloud_provider_type);
457
+ buffer_key_value_urlencode(wb, "&NETDATA_INSTANCE_CLOUD_INSTANCE_TYPE", system_info->cloud_instance_type);
458
+ buffer_key_value_urlencode(wb, "&NETDATA_INSTANCE_CLOUD_INSTANCE_REGION", system_info->cloud_instance_region);
459
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_NAME", system_info->host_os_name);
460
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_ID", system_info->host_os_id);
461
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_ID_LIKE", system_info->host_os_id_like);
462
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_VERSION", system_info->host_os_version);
463
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_VERSION_ID", system_info->host_os_version_id);
464
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_DETECTION", system_info->host_os_detection);
465
+ buffer_key_value_urlencode(wb, "&NETDATA_HOST_IS_K8S_NODE", system_info->is_k8s_node);
466
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_KERNEL_NAME", system_info->kernel_name);
467
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_KERNEL_VERSION", system_info->kernel_version);
468
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_ARCHITECTURE", system_info->architecture);
469
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_VIRTUALIZATION", system_info->virtualization);
470
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_VIRT_DETECTION", system_info->virt_detection);
471
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CONTAINER", system_info->container);
472
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CONTAINER_DETECTION", system_info->container_detection);
473
+ buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_NAME", system_info->container_os_name);
474
+ buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_ID", system_info->container_os_id);
475
+ buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_ID_LIKE", system_info->container_os_id_like);
476
+ buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_VERSION", system_info->container_os_version);
477
+ buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_VERSION_ID", system_info->container_os_version_id);
478
+ buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_DETECTION", system_info->container_os_detection);
479
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT", system_info->host_cores);
480
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CPU_FREQ", system_info->host_cpu_freq);
481
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_TOTAL_RAM", system_info->host_ram_total);
482
+ buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_TOTAL_DISK_SIZE", system_info->host_disk_space);
483
+}
484
+
485
+void rrdhost_system_info_to_node_info(struct rrdhost_system_info *system_info, struct update_node_info *node_info) {
486
+ node_info->data.os_name = system_info->host_os_name;
487
+ node_info->data.os_version = system_info->host_os_version;
488
+ node_info->data.kernel_name = system_info->kernel_name;
489
+ node_info->data.kernel_version = system_info->kernel_version;
490
+ node_info->data.architecture = system_info->architecture;
491
+ node_info->data.cpus = system_info->host_cores ? str2uint32_t(system_info->host_cores, NULL) : 0;
492
+ node_info->data.cpu_frequency = system_info->host_cpu_freq ? system_info->host_cpu_freq : "0";
493
+ node_info->data.memory = system_info->host_ram_total ? system_info->host_ram_total : "0";
494
+ node_info->data.disk_space = system_info->host_disk_space ? system_info->host_disk_space : "0";
495
+ node_info->data.virtualization_type = system_info->virtualization ? system_info->virtualization : "unknown";
496
+ node_info->data.container_type = system_info->container ? system_info->container : "unknown";
497
+ node_info->data.ml_info.ml_capable = system_info->ml_capable;
498
+ node_info->data.ml_info.ml_enabled = system_info->ml_enabled;
499
+}
src/database/rrdhost-system-info.h
new
+99
@@ -0,0 +1,99 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#ifndef NETDATA_RRDHOST_SYSTEM_INFO_H
4
+#define NETDATA_RRDHOST_SYSTEM_INFO_H
5
+
6
+#include "libnetdata/libnetdata.h"
7
+#include "rrdlabels.h"
8
+
9
+#ifdef RRDHOST_SYSTEM_INFO_INTERNALS
10
+struct rrdhost_system_info {
11
+ char *cloud_provider_type;
12
+ char *cloud_instance_type;
13
+ char *cloud_instance_region;
14
+
15
+ char *host_os_name;
16
+ char *host_os_id;
17
+ char *host_os_id_like;
18
+ char *host_os_version;
19
+ char *host_os_version_id;
20
+ char *host_os_detection;
21
+ char *host_cores;
22
+ char *host_cpu_freq;
23
+ char *host_cpu_model;
24
+ char *host_ram_total;
25
+ char *host_disk_space;
26
+ char *container_os_name;
27
+ char *container_os_id;
28
+ char *container_os_id_like;
29
+ char *container_os_version;
30
+ char *container_os_version_id;
31
+ char *container_os_detection;
32
+ char *kernel_name;
33
+ char *kernel_version;
34
+ char *architecture;
35
+ char *virtualization;
36
+ char *virt_detection;
37
+ char *container;
38
+ char *container_detection;
39
+ char *is_k8s_node;
40
+ int16_t hops;
41
+ bool ml_capable;
42
+ bool ml_enabled;
43
+ char *install_type;
44
+ char *prebuilt_arch;
45
+ char *prebuilt_dist;
46
+ int mc_version;
47
+};
48
+#else
49
+struct rrdhost_system_info;
50
+#endif
51
+
52
+// --------------------------------------------------------------------------------------------------------------------
53
+// allocation and free
54
+
55
+struct rrdhost_system_info *rrdhost_system_info_create(void);
56
+void rrdhost_system_info_free(struct rrdhost_system_info *system_info);
57
+
58
+// --------------------------------------------------------------------------------------------------------------------
59
+// importing fields
60
+
61
+// detect system info on current system
62
+int rrdhost_system_info_detect(struct rrdhost_system_info *system_info);
63
+
64
+// import from host rrdlabels
65
+struct rrdhost_system_info *rrdhost_system_info_from_host_labels(RRDLABELS *labels);
66
+
67
+// --------------------------------------------------------------------------------------------------------------------
68
+// setting individual fields
69
+
70
+void rrdhost_system_info_hops_set(struct rrdhost_system_info *si, int16_t hops);
71
+void rrdhost_system_info_ml_capable_set(struct rrdhost_system_info *system_info, bool capable);
72
+void rrdhost_system_info_ml_enabled_set(struct rrdhost_system_info *system_info, bool enabled);
73
+void rrdhost_system_info_mc_version_set(struct rrdhost_system_info *system_info, int version);
74
+
75
+int rrdhost_system_info_set_by_name(struct rrdhost_system_info *system_info, char *name, char *value);
76
+
77
+// --------------------------------------------------------------------------------------------------------------------
78
+// reading individual fields
79
+
80
+const char *rrdhost_system_info_install_type(struct rrdhost_system_info *si);
81
+const char *rrdhost_system_info_prebuilt_dist(struct rrdhost_system_info *si);
82
+int16_t rrdhost_system_info_hops(struct rrdhost_system_info *si);
83
+
84
+// --------------------------------------------------------------------------------------------------------------------
85
+// exporting in various forms
86
+
87
+void rrdhost_system_info_to_rrdlabels(struct rrdhost_system_info *system_info, RRDLABELS *labels);
88
+
89
+void rrdhost_system_info_to_json_v1(BUFFER *wb, struct rrdhost_system_info *system_info);
90
+void rrdhost_system_info_to_json_v2(BUFFER *wb, struct rrdhost_system_info *system_info);
91
+void rrdhost_system_info_to_url_encode_stream(BUFFER *wb, struct rrdhost_system_info *system_info);
92
+
93
+typedef int (*add_host_sysinfo_key_value_t)(const char *name, const char *value, nd_uuid_t *uuid);
94
+int rrdhost_system_info_foreach(struct rrdhost_system_info *system_info, add_host_sysinfo_key_value_t cb, nd_uuid_t *uuid);
95
+
96
+struct update_node_info;
97
+void rrdhost_system_info_to_node_info(struct rrdhost_system_info *system_info, struct update_node_info *node_info);
98
+
99
+#endif //NETDATA_RRDHOST_SYSTEM_INFO_H
src/database/rrdhost.c
+33
-292
@@ -428,9 +428,9 @@ static RRDHOST *rrdhost_create(
428
//
429
430
if (is_localhost && host->system_info) {
431
- host->system_info->ml_capable = ml_capable();
432
- host->system_info->ml_enabled = ml_enabled(host);
433
- host->system_info->mc_version = metric_correlations_version;
431
+ rrdhost_system_info_ml_capable_set(host->system_info, ml_capable());
432
+ rrdhost_system_info_ml_enabled_set(host->system_info, ml_enabled(host));
433
+ rrdhost_system_info_mc_version_set(host->system_info, metric_correlations_version);
434
}
435
436
// ------------------------------------------------------------------------
@@ -670,8 +670,10 @@ RRDHOST *rrdhost_find_or_create(
670
RRDHOST *host = rrdhost_find_by_guid(guid);
671
if (unlikely(host && host->rrd_memory_mode != mode && rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED))) {
672
673
- if (likely(!archived && rrdhost_flag_check(host, RRDHOST_FLAG_PENDING_CONTEXT_LOAD)))
673
+ if (likely(!archived && rrdhost_flag_check(host, RRDHOST_FLAG_PENDING_CONTEXT_LOAD))) {
674
+ rrdhost_system_info_free(system_info);
675
return host;
676
+ }
677
678
/* If a legacy memory mode instantiates all dbengine state must be discarded to avoid inconsistencies */
679
nd_log(NDLS_DAEMON, NDLP_INFO,
@@ -740,6 +742,9 @@ RRDHOST *rrdhost_find_or_create(
742
, system_info);
743
}
744
745
+ if(!host)
746
+ rrdhost_system_info_free(system_info);
747
+
748
return host;
749
}
750
@@ -872,45 +877,6 @@ int rrd_init(const char *hostname, struct rrdhost_system_info *system_info, bool
877
// ----------------------------------------------------------------------------
878
// RRDHOST - free
879
875
-void rrdhost_system_info_free(struct rrdhost_system_info *system_info) {
876
- if(likely(system_info)) {
877
- __atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
878
-
879
- freez(system_info->cloud_provider_type);
880
- freez(system_info->cloud_instance_type);
881
- freez(system_info->cloud_instance_region);
882
- freez(system_info->host_os_name);
883
- freez(system_info->host_os_id);
884
- freez(system_info->host_os_id_like);
885
- freez(system_info->host_os_version);
886
- freez(system_info->host_os_version_id);
887
- freez(system_info->host_os_detection);
888
- freez(system_info->host_cores);
889
- freez(system_info->host_cpu_freq);
890
- freez(system_info->host_cpu_model);
891
- freez(system_info->host_ram_total);
892
- freez(system_info->host_disk_space);
893
- freez(system_info->container_os_name);
894
- freez(system_info->container_os_id);
895
- freez(system_info->container_os_id_like);
896
- freez(system_info->container_os_version);
897
- freez(system_info->container_os_version_id);
898
- freez(system_info->container_os_detection);
899
- freez(system_info->kernel_name);
900
- freez(system_info->kernel_version);
901
- freez(system_info->architecture);
902
- freez(system_info->virtualization);
903
- freez(system_info->virt_detection);
904
- freez(system_info->container);
905
- freez(system_info->container_detection);
906
- freez(system_info->is_k8s_node);
907
- freez(system_info->install_type);
908
- freez(system_info->prebuilt_arch);
909
- freez(system_info->prebuilt_dist);
910
- freez(system_info);
911
- }
912
-}
913
-
880
void rrdhost_free___while_having_rrd_wrlock(RRDHOST *host, bool force) {
881
if(!host) return;
882
@@ -1026,117 +992,6 @@ void rrd_finalize_collection_for_all_hosts(void) {
992
dfe_done(host);
993
}
994
1029
-struct rrdhost_system_info *rrdhost_labels_to_system_info(RRDLABELS *labels) {
1030
- struct rrdhost_system_info *info = callocz(1, sizeof(struct rrdhost_system_info));
1031
- info->hops = 1;
1032
-
1033
- rrdlabels_get_value_strdup_or_null(labels, &info->cloud_provider_type, "_cloud_provider_type");
1034
- rrdlabels_get_value_strdup_or_null(labels, &info->cloud_instance_type, "_cloud_instance_type");
1035
- rrdlabels_get_value_strdup_or_null(labels, &info->cloud_instance_region, "_cloud_instance_region");
1036
- rrdlabels_get_value_strdup_or_null(labels, &info->host_os_name, "_os_name");
1037
- rrdlabels_get_value_strdup_or_null(labels, &info->host_os_version, "_os_version");
1038
- rrdlabels_get_value_strdup_or_null(labels, &info->kernel_version, "_kernel_version");
1039
- rrdlabels_get_value_strdup_or_null(labels, &info->host_cores, "_system_cores");
1040
- rrdlabels_get_value_strdup_or_null(labels, &info->host_cpu_freq, "_system_cpu_freq");
1041
- rrdlabels_get_value_strdup_or_null(labels, &info->host_cpu_model, "_system_cpu_model");
1042
- rrdlabels_get_value_strdup_or_null(labels, &info->host_ram_total, "_system_ram_total");
1043
- rrdlabels_get_value_strdup_or_null(labels, &info->host_disk_space, "_system_disk_space");
1044
- rrdlabels_get_value_strdup_or_null(labels, &info->architecture, "_architecture");
1045
- rrdlabels_get_value_strdup_or_null(labels, &info->virtualization, "_virtualization");
1046
- rrdlabels_get_value_strdup_or_null(labels, &info->container, "_container");
1047
- rrdlabels_get_value_strdup_or_null(labels, &info->container_detection, "_container_detection");
1048
- rrdlabels_get_value_strdup_or_null(labels, &info->virt_detection, "_virt_detection");
1049
- rrdlabels_get_value_strdup_or_null(labels, &info->is_k8s_node, "_is_k8s_node");
1050
- rrdlabels_get_value_strdup_or_null(labels, &info->install_type, "_install_type");
1051
- rrdlabels_get_value_strdup_or_null(labels, &info->prebuilt_arch, "_prebuilt_arch");
1052
- rrdlabels_get_value_strdup_or_null(labels, &info->prebuilt_dist, "_prebuilt_dist");
1053
-
1054
- return info;
1055
-}
1056
-
1057
-static void rrdhost_load_auto_labels(void) {
1058
- RRDLABELS *labels = localhost->rrdlabels;
1059
-
1060
- if (localhost->system_info->cloud_provider_type)
1061
- rrdlabels_add(labels, "_cloud_provider_type", localhost->system_info->cloud_provider_type, RRDLABEL_SRC_AUTO);
1062
-
1063
- if (localhost->system_info->cloud_instance_type)
1064
- rrdlabels_add(labels, "_cloud_instance_type", localhost->system_info->cloud_instance_type, RRDLABEL_SRC_AUTO);
1065
-
1066
- if (localhost->system_info->cloud_instance_region)
1067
- rrdlabels_add(labels, "_cloud_instance_region", localhost->system_info->cloud_instance_region, RRDLABEL_SRC_AUTO);
1068
-
1069
- if (localhost->system_info->host_os_name)
1070
- rrdlabels_add(labels, "_os_name", localhost->system_info->host_os_name, RRDLABEL_SRC_AUTO);
1071
-
1072
- if (localhost->system_info->host_os_version)
1073
- rrdlabels_add(labels, "_os_version", localhost->system_info->host_os_version, RRDLABEL_SRC_AUTO);
1074
-
1075
- if (localhost->system_info->kernel_version)
1076
- rrdlabels_add(labels, "_kernel_version", localhost->system_info->kernel_version, RRDLABEL_SRC_AUTO);
1077
-
1078
- if (localhost->system_info->host_cores)
1079
- rrdlabels_add(labels, "_system_cores", localhost->system_info->host_cores, RRDLABEL_SRC_AUTO);
1080
-
1081
- if (localhost->system_info->host_cpu_freq)
1082
- rrdlabels_add(labels, "_system_cpu_freq", localhost->system_info->host_cpu_freq, RRDLABEL_SRC_AUTO);
1083
-
1084
- if (localhost->system_info->host_cpu_model)
1085
- rrdlabels_add(labels, "_system_cpu_model", localhost->system_info->host_cpu_model, RRDLABEL_SRC_AUTO);
1086
-
1087
- if (localhost->system_info->host_ram_total)
1088
- rrdlabels_add(labels, "_system_ram_total", localhost->system_info->host_ram_total, RRDLABEL_SRC_AUTO);
1089
-
1090
- if (localhost->system_info->host_disk_space)
1091
- rrdlabels_add(labels, "_system_disk_space", localhost->system_info->host_disk_space, RRDLABEL_SRC_AUTO);
1092
-
1093
- if (localhost->system_info->architecture)
1094
- rrdlabels_add(labels, "_architecture", localhost->system_info->architecture, RRDLABEL_SRC_AUTO);
1095
-
1096
- if (localhost->system_info->virtualization)
1097
- rrdlabels_add(labels, "_virtualization", localhost->system_info->virtualization, RRDLABEL_SRC_AUTO);
1098
-
1099
- if (localhost->system_info->container)
1100
- rrdlabels_add(labels, "_container", localhost->system_info->container, RRDLABEL_SRC_AUTO);
1101
-
1102
- if (localhost->system_info->container_detection)
1103
- rrdlabels_add(labels, "_container_detection", localhost->system_info->container_detection, RRDLABEL_SRC_AUTO);
1104
-
1105
- if (localhost->system_info->virt_detection)
1106
- rrdlabels_add(labels, "_virt_detection", localhost->system_info->virt_detection, RRDLABEL_SRC_AUTO);
1107
-
1108
- if (localhost->system_info->is_k8s_node)
1109
- rrdlabels_add(labels, "_is_k8s_node", localhost->system_info->is_k8s_node, RRDLABEL_SRC_AUTO);
1110
-
1111
- if (localhost->system_info->install_type)
1112
- rrdlabels_add(labels, "_install_type", localhost->system_info->install_type, RRDLABEL_SRC_AUTO);
1113
-
1114
- if (localhost->system_info->prebuilt_arch)
1115
- rrdlabels_add(labels, "_prebuilt_arch", localhost->system_info->prebuilt_arch, RRDLABEL_SRC_AUTO);
1116
-
1117
- if (localhost->system_info->prebuilt_dist)
1118
- rrdlabels_add(labels, "_prebuilt_dist", localhost->system_info->prebuilt_dist, RRDLABEL_SRC_AUTO);
1119
-
1120
- add_aclk_host_labels();
1121
-
1122
- // The source should be CONF, but when it is set, these labels are exported by default ('send configured labels' in exporting.conf).
1123
- // Their export seems to break exporting to Graphite, see https://github.com/netdata/netdata/issues/14084.
1124
-
1125
- int is_ephemeral = appconfig_get_boolean(&netdata_config, CONFIG_SECTION_GLOBAL, "is ephemeral node", CONFIG_BOOLEAN_NO);
1126
- rrdlabels_add(labels, "_is_ephemeral", is_ephemeral ? "true" : "false", RRDLABEL_SRC_AUTO);
1127
-
1128
- int has_unstable_connection = appconfig_get_boolean(&netdata_config, CONFIG_SECTION_GLOBAL, "has unstable connection", CONFIG_BOOLEAN_NO);
1129
- rrdlabels_add(labels, "_has_unstable_connection", has_unstable_connection ? "true" : "false", RRDLABEL_SRC_AUTO);
1130
-
1131
- rrdlabels_add(labels, "_is_parent", (stream_receivers_currently_connected() > 0) ? "true" : "false", RRDLABEL_SRC_AUTO);
1132
-
1133
- rrdlabels_add(labels, "_hostname", string2str(localhost->hostname), RRDLABEL_SRC_AUTO);
1134
- rrdlabels_add(labels, "_os", string2str(localhost->os), RRDLABEL_SRC_AUTO);
1135
-
1136
- if (localhost->stream.snd.destination)
1137
- rrdlabels_add(labels, "_streams_to", string2str(localhost->stream.snd.destination), RRDLABEL_SRC_AUTO);
1138
-}
1139
-
995
void rrdhost_set_is_parent_label(void) {
996
uint32_t count = stream_receivers_currently_connected();
997
@@ -1194,6 +1049,30 @@ static void rrdhost_load_kubernetes_labels(void) {
1049
label_script);
1050
}
1051
1052
+static void rrdhost_load_auto_labels(void) {
1053
+ RRDLABELS *labels = localhost->rrdlabels;
1054
+
1055
+ rrdhost_system_info_to_rrdlabels(localhost->system_info, labels);
1056
+ add_aclk_host_labels();
1057
+
1058
+ // The source should be CONF, but when it is set, these labels are exported by default ('send configured labels' in exporting.conf).
1059
+ // Their export seems to break exporting to Graphite, see https://github.com/netdata/netdata/issues/14084.
1060
+
1061
+ int is_ephemeral = appconfig_get_boolean(&netdata_config, CONFIG_SECTION_GLOBAL, "is ephemeral node", CONFIG_BOOLEAN_NO);
1062
+ rrdlabels_add(labels, "_is_ephemeral", is_ephemeral ? "true" : "false", RRDLABEL_SRC_AUTO);
1063
+
1064
+ int has_unstable_connection = appconfig_get_boolean(&netdata_config, CONFIG_SECTION_GLOBAL, "has unstable connection", CONFIG_BOOLEAN_NO);
1065
+ rrdlabels_add(labels, "_has_unstable_connection", has_unstable_connection ? "true" : "false", RRDLABEL_SRC_AUTO);
1066
+
1067
+ rrdlabels_add(labels, "_is_parent", (stream_receivers_currently_connected() > 0) ? "true" : "false", RRDLABEL_SRC_AUTO);
1068
+
1069
+ rrdlabels_add(labels, "_hostname", string2str(localhost->hostname), RRDLABEL_SRC_AUTO);
1070
+ rrdlabels_add(labels, "_os", string2str(localhost->os), RRDLABEL_SRC_AUTO);
1071
+
1072
+ if (localhost->stream.snd.destination)
1073
+ rrdlabels_add(labels, "_streams_to", string2str(localhost->stream.snd.destination), RRDLABEL_SRC_AUTO);
1074
+}
1075
+
1076
void reload_host_labels(void) {
1077
if(!localhost->rrdlabels)
1078
localhost->rrdlabels = rrdlabels_create();
@@ -1227,144 +1106,6 @@ void rrdhost_finalize_collection(RRDHOST *host) {
1106
rrdset_foreach_done(st);
1107
}
1108
1230
-// ----------------------------------------------------------------------------
1231
-// RRDHOST - set system info from environment variables
1232
-// system_info fields must be heap allocated or NULL
1233
-int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value) {
1234
- int res = 0;
1235
-
1236
- if (!strcmp(name, "NETDATA_PROTOCOL_VERSION"))
1237
- return res;
1238
- else if(!strcmp(name, "NETDATA_INSTANCE_CLOUD_TYPE")){
1239
- freez(system_info->cloud_provider_type);
1240
- system_info->cloud_provider_type = strdupz(value);
1241
- }
1242
- else if(!strcmp(name, "NETDATA_INSTANCE_CLOUD_INSTANCE_TYPE")){
1243
- freez(system_info->cloud_instance_type);
1244
- system_info->cloud_instance_type = strdupz(value);
1245
- }
1246
- else if(!strcmp(name, "NETDATA_INSTANCE_CLOUD_INSTANCE_REGION")){
1247
- freez(system_info->cloud_instance_region);
1248
- system_info->cloud_instance_region = strdupz(value);
1249
- }
1250
- else if(!strcmp(name, "NETDATA_CONTAINER_OS_NAME")){
1251
- freez(system_info->container_os_name);
1252
- system_info->container_os_name = strdupz(value);
1253
- }
1254
- else if(!strcmp(name, "NETDATA_CONTAINER_OS_ID")){
1255
- freez(system_info->container_os_id);
1256
- system_info->container_os_id = strdupz(value);
1257
- }
1258
- else if(!strcmp(name, "NETDATA_CONTAINER_OS_ID_LIKE")){
1259
- freez(system_info->container_os_id_like);
1260
- system_info->container_os_id_like = strdupz(value);
1261
- }
1262
- else if(!strcmp(name, "NETDATA_CONTAINER_OS_VERSION")){
1263
- freez(system_info->container_os_version);
1264
- system_info->container_os_version = strdupz(value);
1265
- }
1266
- else if(!strcmp(name, "NETDATA_CONTAINER_OS_VERSION_ID")){
1267
- freez(system_info->container_os_version_id);
1268
- system_info->container_os_version_id = strdupz(value);
1269
- }
1270
- else if(!strcmp(name, "NETDATA_CONTAINER_OS_DETECTION")){
1271
- freez(system_info->container_os_detection);
1272
- system_info->container_os_detection = strdupz(value);
1273
- }
1274
- else if(!strcmp(name, "NETDATA_HOST_OS_NAME")){
1275
- freez(system_info->host_os_name);
1276
- system_info->host_os_name = strdupz(value);
1277
- json_fix_string(system_info->host_os_name);
1278
- }
1279
- else if(!strcmp(name, "NETDATA_HOST_OS_ID")){
1280
- freez(system_info->host_os_id);
1281
- system_info->host_os_id = strdupz(value);
1282
- }
1283
- else if(!strcmp(name, "NETDATA_HOST_OS_ID_LIKE")){
1284
- freez(system_info->host_os_id_like);
1285
- system_info->host_os_id_like = strdupz(value);
1286
- }
1287
- else if(!strcmp(name, "NETDATA_HOST_OS_VERSION")){
1288
- freez(system_info->host_os_version);
1289
- system_info->host_os_version = strdupz(value);
1290
- }
1291
- else if(!strcmp(name, "NETDATA_HOST_OS_VERSION_ID")){
1292
- freez(system_info->host_os_version_id);
1293
- system_info->host_os_version_id = strdupz(value);
1294
- }
1295
- else if(!strcmp(name, "NETDATA_HOST_OS_DETECTION")){
1296
- freez(system_info->host_os_detection);
1297
- system_info->host_os_detection = strdupz(value);
1298
- }
1299
- else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_NAME")){
1300
- freez(system_info->kernel_name);
1301
- system_info->kernel_name = strdupz(value);
1302
- }
1303
- else if(!strcmp(name, "NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT")){
1304
- freez(system_info->host_cores);
1305
- system_info->host_cores = strdupz(value);
1306
- }
1307
- else if(!strcmp(name, "NETDATA_SYSTEM_CPU_FREQ")){
1308
- freez(system_info->host_cpu_freq);
1309
- system_info->host_cpu_freq = strdupz(value);
1310
- }
1311
- else if (!strcmp(name, "NETDATA_SYSTEM_CPU_MODEL")){
1312
- freez(system_info->host_cpu_model);
1313
- system_info->host_cpu_model = strdupz(value);
1314
- }
1315
- else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_RAM")){
1316
- freez(system_info->host_ram_total);
1317
- system_info->host_ram_total = strdupz(value);
1318
- }
1319
- else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_DISK_SIZE")){
1320
- freez(system_info->host_disk_space);
1321
- system_info->host_disk_space = strdupz(value);
1322
- }
1323
- else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_VERSION")){
1324
- freez(system_info->kernel_version);
1325
- system_info->kernel_version = strdupz(value);
1326
- }
1327
- else if(!strcmp(name, "NETDATA_SYSTEM_ARCHITECTURE")){
1328
- freez(system_info->architecture);
1329
- system_info->architecture = strdupz(value);
1330
- }
1331
- else if(!strcmp(name, "NETDATA_SYSTEM_VIRTUALIZATION")){
1332
- freez(system_info->virtualization);
1333
- system_info->virtualization = strdupz(value);
1334
- }
1335
- else if(!strcmp(name, "NETDATA_SYSTEM_VIRT_DETECTION")){
1336
- freez(system_info->virt_detection);
1337
- system_info->virt_detection = strdupz(value);
1338
- }
1339
- else if(!strcmp(name, "NETDATA_SYSTEM_CONTAINER")){
1340
- freez(system_info->container);
1341
- system_info->container = strdupz(value);
1342
- }
1343
- else if(!strcmp(name, "NETDATA_SYSTEM_CONTAINER_DETECTION")){
1344
- freez(system_info->container_detection);
1345
- system_info->container_detection = strdupz(value);
1346
- }
1347
- else if(!strcmp(name, "NETDATA_HOST_IS_K8S_NODE")){
1348
- freez(system_info->is_k8s_node);
1349
- system_info->is_k8s_node = strdupz(value);
1350
- }
1351
- else if (!strcmp(name, "NETDATA_SYSTEM_CPU_VENDOR"))
1352
- return res;
1353
- else if (!strcmp(name, "NETDATA_SYSTEM_CPU_DETECTION"))
1354
- return res;
1355
- else if (!strcmp(name, "NETDATA_SYSTEM_RAM_DETECTION"))
1356
- return res;
1357
- else if (!strcmp(name, "NETDATA_SYSTEM_DISK_DETECTION"))
1358
- return res;
1359
- else if (!strcmp(name, "NETDATA_CONTAINER_IS_OFFICIAL_IMAGE"))
1360
- return res;
1361
- else {
1362
- res = 1;
1363
- }
1364
-
1365
- return res;
1366
-}
1367
-
1109
bool rrdhost_matches_window(RRDHOST *host, time_t after, time_t before, time_t now) {
1110
time_t first_time_s, last_time_s;
1111
rrdhost_retention(host, now, rrdhost_is_online(host), &first_time_s, &last_time_s);
src/database/rrdlabels.h
+4
-1
@@ -3,7 +3,7 @@
3
#ifndef NETDATA_RRDLABELS_H
4
#define NETDATA_RRDLABELS_H
5
6
-#include "rrd.h"
6
+#include "libnetdata/libnetdata.h"
7
8
struct pattern_array_item {
9
Word_t size;
@@ -30,6 +30,9 @@ typedef enum __attribute__ ((__packed__)) rrdlabel_source {
30
31
#define RRDLABEL_FLAG_INTERNAL (RRDLABEL_FLAG_OLD | RRDLABEL_FLAG_NEW | RRDLABEL_FLAG_DONT_DELETE)
32
33
+struct rrdlabels;
34
+typedef struct rrdlabels RRDLABELS;
35
+
36
RRDLABELS *rrdlabels_create(void);
37
void rrdlabels_destroy(RRDLABELS *labels_dict);
38
void rrdlabels_add(RRDLABELS *labels, const char *name, const char *value, RRDLABEL_SRC ls);
src/database/sqlite/sqlite_aclk.c
+2
-3
@@ -113,10 +113,9 @@ static int create_host_callback(void *data, int argc, char **argv, char **column
113
return 0;
114
}
115
116
- struct rrdhost_system_info *system_info = callocz(1, sizeof(struct rrdhost_system_info));
117
- __atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
116
+ struct rrdhost_system_info *system_info = rrdhost_system_info_create();
117
119
- system_info->hops = (int16_t)str2i((const char *) argv[IDX_HOPS]);
118
+ rrdhost_system_info_hops_set(system_info, (int16_t)str2i((const char *) argv[IDX_HOPS]));
119
120
sql_build_host_system_info((nd_uuid_t *)argv[IDX_HOST_ID], system_info);
121
src/database/sqlite/sqlite_aclk_node.c
+2
-16
@@ -70,30 +70,16 @@ static void build_node_info(RRDHOST *host)
70
71
node_info.data.name = rrdhost_hostname(host);
72
node_info.data.os = rrdhost_os(host);
73
- node_info.data.os_name = host->system_info->host_os_name;
74
- node_info.data.os_version = host->system_info->host_os_version;
75
- node_info.data.kernel_name = host->system_info->kernel_name;
76
- node_info.data.kernel_version = host->system_info->kernel_version;
77
- node_info.data.architecture = host->system_info->architecture;
78
- node_info.data.cpus = host->system_info->host_cores ? str2uint32_t(host->system_info->host_cores, NULL) : 0;
79
- node_info.data.cpu_frequency = host->system_info->host_cpu_freq ? host->system_info->host_cpu_freq : "0";
80
- node_info.data.memory = host->system_info->host_ram_total ? host->system_info->host_ram_total : "0";
81
- node_info.data.disk_space = host->system_info->host_disk_space ? host->system_info->host_disk_space : "0";
73
node_info.data.version = host_version ? host_version : NETDATA_VERSION;
74
node_info.data.release_channel = get_release_channel();
75
node_info.data.timezone = rrdhost_abbrev_timezone(host);
85
- node_info.data.virtualization_type = host->system_info->virtualization ? host->system_info->virtualization : "unknown";
86
- node_info.data.container_type = host->system_info->container ? host->system_info->container : "unknown";
76
node_info.data.custom_info = config_get(CONFIG_SECTION_WEB, "custom dashboard_info.js", "");
77
node_info.data.machine_guid = host->machine_guid;
89
-
78
node_info.node_capabilities = (struct capability *)aclk_get_agent_capas();
91
-
92
- node_info.data.ml_info.ml_capable = host->system_info->ml_capable;
93
- node_info.data.ml_info.ml_enabled = host->system_info->ml_enabled;
94
-
79
node_info.data.host_labels_ptr = host->rrdlabels;
80
81
+ rrdhost_system_info_to_node_info(host->system_info, &node_info);
82
+
83
aclk_update_node_info(&node_info);
84
nd_log(
85
NDLS_ACCESS,
src/database/sqlite/sqlite_metadata.c
+4
-31
@@ -460,7 +460,7 @@ struct node_instance_list *get_node_list(void)
460
node_list[row].queryable = 1;
461
node_list[row].live =
462
(host == localhost || host->receiver || !(rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN))) ? 1 : 0;
463
- node_list[row].hops = host->system_info ? host->system_info->hops :
463
+ node_list[row].hops = host->system_info ? rrdhost_system_info_hops(host->system_info) :
464
uuid_eq(*host_id, localhost->host_id.uuid) ? 0 : 1;
465
node_list[row].hostname =
466
sqlite3_column_bytes(res, 2) ? strdupz((char *)sqlite3_column_text(res, 2)) : NULL;
@@ -520,7 +520,7 @@ void sql_build_host_system_info(nd_uuid_t *host_id, struct rrdhost_system_info *
520
521
param = 0;
522
while (sqlite3_step_monitored(res) == SQLITE_ROW) {
523
- rrdhost_set_system_info_variable(
523
+ rrdhost_system_info_set_by_name(
524
system_info, (char *)sqlite3_column_text(res, 0), (char *)sqlite3_column_text(res, 1));
525
}
526
@@ -957,7 +957,7 @@ static int store_host_metadata(RRDHOST *host)
957
SQLITE_BIND_FAIL(bind_fail, bind_text_null(res, ++param, rrdhost_os(host), 1));
958
SQLITE_BIND_FAIL(bind_fail, bind_text_null(res, ++param, rrdhost_timezone(host), 1));
959
SQLITE_BIND_FAIL(bind_fail, bind_text_null(res, ++param, "", 1));
960
- SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int(res, ++param, host->system_info ? host->system_info->hops : 0));
960
+ SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int(res, ++param, host->system_info ? rrdhost_system_info_hops(host->system_info) : 0));
961
SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int(res, ++param, host->rrd_memory_mode));
962
SQLITE_BIND_FAIL(bind_fail, bind_text_null(res, ++param, rrdhost_abbrev_timezone(host), 1));
963
SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int(res, ++param, host->utc_offset));
@@ -1018,34 +1018,7 @@ static bool store_host_systeminfo(RRDHOST *host)
1018
if (unlikely(!system_info))
1019
return false;
1020
1021
- int ret = 0;
1022
-
1023
- ret += add_host_sysinfo_key_value("NETDATA_CONTAINER_OS_NAME", system_info->container_os_name, &host->host_id.uuid);
1024
- ret += add_host_sysinfo_key_value("NETDATA_CONTAINER_OS_ID", system_info->container_os_id, &host->host_id.uuid);
1025
- ret += add_host_sysinfo_key_value("NETDATA_CONTAINER_OS_ID_LIKE", system_info->container_os_id_like, &host->host_id.uuid);
1026
- ret += add_host_sysinfo_key_value("NETDATA_CONTAINER_OS_VERSION", system_info->container_os_version, &host->host_id.uuid);
1027
- ret += add_host_sysinfo_key_value("NETDATA_CONTAINER_OS_VERSION_ID", system_info->container_os_version_id, &host->host_id.uuid);
1028
- ret += add_host_sysinfo_key_value("NETDATA_CONTAINER_OS_DETECTION", system_info->host_os_detection, &host->host_id.uuid);
1029
- ret += add_host_sysinfo_key_value("NETDATA_HOST_OS_NAME", system_info->host_os_name, &host->host_id.uuid);
1030
- ret += add_host_sysinfo_key_value("NETDATA_HOST_OS_ID", system_info->host_os_id, &host->host_id.uuid);
1031
- ret += add_host_sysinfo_key_value("NETDATA_HOST_OS_ID_LIKE", system_info->host_os_id_like, &host->host_id.uuid);
1032
- ret += add_host_sysinfo_key_value("NETDATA_HOST_OS_VERSION", system_info->host_os_version, &host->host_id.uuid);
1033
- ret += add_host_sysinfo_key_value("NETDATA_HOST_OS_VERSION_ID", system_info->host_os_version_id, &host->host_id.uuid);
1034
- ret += add_host_sysinfo_key_value("NETDATA_HOST_OS_DETECTION", system_info->host_os_detection, &host->host_id.uuid);
1035
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_KERNEL_NAME", system_info->kernel_name, &host->host_id.uuid);
1036
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT", system_info->host_cores, &host->host_id.uuid);
1037
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_CPU_FREQ", system_info->host_cpu_freq, &host->host_id.uuid);
1038
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_TOTAL_RAM", system_info->host_ram_total, &host->host_id.uuid);
1039
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_TOTAL_DISK_SIZE", system_info->host_disk_space, &host->host_id.uuid);
1040
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_KERNEL_VERSION", system_info->kernel_version, &host->host_id.uuid);
1041
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_ARCHITECTURE", system_info->architecture, &host->host_id.uuid);
1042
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_VIRTUALIZATION", system_info->virtualization, &host->host_id.uuid);
1043
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_VIRT_DETECTION", system_info->virt_detection, &host->host_id.uuid);
1044
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_CONTAINER", system_info->container, &host->host_id.uuid);
1045
- ret += add_host_sysinfo_key_value("NETDATA_SYSTEM_CONTAINER_DETECTION", system_info->container_detection, &host->host_id.uuid);
1046
- ret += add_host_sysinfo_key_value("NETDATA_HOST_IS_K8S_NODE", system_info->is_k8s_node, &host->host_id.uuid);
1047
-
1048
- return !(24 == ret);
1021
+ return (24 != rrdhost_system_info_foreach(system_info, add_host_sysinfo_key_value, &host->host_id.uuid));
1022
}
1023
1024
src/libnetdata/buffer/buffer.h
+12
@@ -1294,4 +1294,16 @@ static inline BUFFER *buffer_dup(BUFFER *src) {
1294
return dst;
1295
}
1296
1297
+char *url_encode(const char *str);
1298
+static inline void buffer_key_value_urlencode(BUFFER *wb, const char *key, const char *value) {
1299
+ char *encoded = NULL;
1300
+
1301
+ if(value && *value)
1302
+ encoded = url_encode(value);
1303
+
1304
+ buffer_sprintf(wb, "%s=%s", key, encoded ? encoded : "");
1305
+
1306
+ freez(encoded);
1307
+}
1308
+
1309
#endif /* NETDATA_WEB_BUFFER_H */
src/plugins.d/pluginsd_parser.c
+1
-1
@@ -200,7 +200,7 @@ static inline PARSER_RC pluginsd_host_define_end(char **words __maybe_unused, si
200
stream_receive.replication.enabled,
201
stream_receive.replication.period,
202
stream_receive.replication.step,
203
- rrdhost_labels_to_system_info(parser->user.host_define.rrdlabels),
203
+ rrdhost_system_info_from_host_labels(parser->user.host_define.rrdlabels),
204
false);
205
206
rrdhost_option_set(host, RRDHOST_OPTION_VIRTUAL_HOST);
src/streaming/rrdhost-status.c
+1
-1
@@ -130,7 +130,7 @@ void rrdhost_status(RRDHOST *host, time_t now, RRDHOST_STATUS *s) {
130
s->ingest.reason = (online) ? STREAM_HANDSHAKE_NEVER : host->stream.rcv.status.exit_reason;
131
132
rrdhost_receiver_lock(host);
133
- s->ingest.hops = (int16_t)(host->system_info ? host->system_info->hops : (host == localhost) ? 0 : 1);
133
+ s->ingest.hops = (int16_t)(host->system_info ? rrdhost_system_info_hops(host->system_info) : (host == localhost) ? 0 : 1);
134
bool has_receiver = false;
135
if (host->receiver && rrdhost_flag_check(host, RRDHOST_FLAG_COLLECTOR_ONLINE)) {
136
has_receiver = true;
src/streaming/stream-connector.c
+2
-42
@@ -266,17 +266,6 @@ stream_connect_validate_first_response(RRDHOST *host, struct sender_state *s, ch
266
return false;
267
}
268
269
-static inline void buffer_key_value_urlencode(BUFFER *wb, const char *key, const char *value) {
270
- char *encoded = NULL;
271
-
272
- if(value && *value)
273
- encoded = url_encode(value);
274
-
275
- buffer_sprintf(wb, "%s=%s", key, encoded ? encoded : "");
276
-
277
- freez(encoded);
278
-}
279
-
269
bool stream_connect(struct sender_state *s, uint16_t default_port, time_t timeout) {
270
worker_is_busy(WORKER_SENDER_CONNECTOR_JOB_CONNECTING);
271
@@ -285,7 +274,7 @@ bool stream_connect(struct sender_state *s, uint16_t default_port, time_t timeou
274
// make sure the socket is closed
275
nd_sock_close(&s->sock);
276
288
- s->hops = (int16_t)(host->system_info->hops + 1);
277
+ s->hops = (int16_t)(rrdhost_system_info_hops(host->system_info) + 1);
278
279
// reset this to make sure we have its current value
280
s->sock.verify_certificate = netdata_ssl_validate_certificate_sender;
@@ -322,37 +311,8 @@ bool stream_connect(struct sender_state *s, uint16_t default_port, time_t timeou
311
buffer_key_value_urlencode(wb, "&abbrev_timezone", rrdhost_abbrev_timezone(host));
312
buffer_sprintf(wb, "&utc_offset=%d", host->utc_offset);
313
buffer_sprintf(wb, "&hops=%d", s->hops);
325
- buffer_sprintf(wb, "&ml_capable=%d", host->system_info->ml_capable);
326
- buffer_sprintf(wb, "&ml_enabled=%d", host->system_info->ml_enabled);
327
- buffer_sprintf(wb, "&mc_version=%d", host->system_info->mc_version);
314
buffer_sprintf(wb, "&ver=%u", s->capabilities);
329
- buffer_key_value_urlencode(wb, "&NETDATA_INSTANCE_CLOUD_TYPE", host->system_info->cloud_provider_type);
330
- buffer_key_value_urlencode(wb, "&NETDATA_INSTANCE_CLOUD_INSTANCE_TYPE", host->system_info->cloud_instance_type);
331
- buffer_key_value_urlencode(wb, "&NETDATA_INSTANCE_CLOUD_INSTANCE_REGION", host->system_info->cloud_instance_region);
332
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_NAME", host->system_info->host_os_name);
333
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_ID", host->system_info->host_os_id);
334
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_ID_LIKE", host->system_info->host_os_id_like);
335
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_VERSION", host->system_info->host_os_version);
336
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_VERSION_ID", host->system_info->host_os_version_id);
337
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_OS_DETECTION", host->system_info->host_os_detection);
338
- buffer_key_value_urlencode(wb, "&NETDATA_HOST_IS_K8S_NODE", host->system_info->is_k8s_node);
339
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_KERNEL_NAME", host->system_info->kernel_name);
340
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_KERNEL_VERSION", host->system_info->kernel_version);
341
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_ARCHITECTURE", host->system_info->architecture);
342
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_VIRTUALIZATION", host->system_info->virtualization);
343
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_VIRT_DETECTION", host->system_info->virt_detection);
344
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CONTAINER", host->system_info->container);
345
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CONTAINER_DETECTION", host->system_info->container_detection);
346
- buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_NAME", host->system_info->container_os_name);
347
- buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_ID", host->system_info->container_os_id);
348
- buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_ID_LIKE", host->system_info->container_os_id_like);
349
- buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_VERSION", host->system_info->container_os_version);
350
- buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_VERSION_ID", host->system_info->container_os_version_id);
351
- buffer_key_value_urlencode(wb, "&NETDATA_CONTAINER_OS_DETECTION", host->system_info->container_os_detection);
352
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT", host->system_info->host_cores);
353
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_CPU_FREQ", host->system_info->host_cpu_freq);
354
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_TOTAL_RAM", host->system_info->host_ram_total);
355
- buffer_key_value_urlencode(wb, "&NETDATA_SYSTEM_TOTAL_DISK_SIZE", host->system_info->host_disk_space);
315
+ rrdhost_system_info_to_url_encode_stream(wb, host->system_info);
316
buffer_key_value_urlencode(wb, "&NETDATA_PROTOCOL_VERSION", STREAMING_PROTOCOL_VERSION);
317
buffer_strcat(wb, HTTP_1_1 HTTP_ENDL);
318
buffer_sprintf(wb, "User-Agent: %s/%s" HTTP_ENDL, rrdhost_program_name(host), rrdhost_program_version(host));
src/streaming/stream-receiver-connection.c
+12
-13
@@ -140,6 +140,8 @@ static bool stream_receiver_send_first_response(struct receiver_state *rpt) {
140
rpt->config.replication.step,
141
rpt->system_info,
142
0);
143
+ // IMPORTANT: system_info is now consumed!
144
+ rpt->system_info = NULL;
145
146
if(!host) {
147
stream_receiver_log_status(
@@ -150,10 +152,6 @@ static bool stream_receiver_send_first_response(struct receiver_state *rpt) {
152
stream_send_error_on_taken_over_connection(rpt, START_STREAMING_ERROR_INTERNAL_ERROR);
153
return false;
154
}
153
- // IMPORTANT: KEEP THIS FIRST AFTER CHECKING host RESPONSE!
154
- // THIS IS HOW WE KNOW THE system_info IS GONE NOW...
155
- // system_info has been consumed by the host structure
156
- rpt->system_info = NULL;
155
156
if (unlikely(rrdhost_flag_check(host, RRDHOST_FLAG_PENDING_CONTEXT_LOAD))) {
157
stream_receiver_log_status(
@@ -291,10 +289,9 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
289
#endif
290
291
__atomic_add_fetch(&netdata_buffers_statistics.rrdhost_receivers, sizeof(*rpt), __ATOMIC_RELAXED);
294
- __atomic_add_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
292
296
- rpt->system_info = callocz(1, sizeof(struct rrdhost_system_info));
297
- rpt->system_info->hops = rpt->hops;
293
+ rpt->system_info = rrdhost_system_info_create();
294
+ rrdhost_system_info_hops_set(rpt->system_info, rpt->hops);
295
296
nd_sock_init(&rpt->sock, netdata_ssl_web_server_ctx, false);
297
rpt->client_ip = strdupz(w->client_ip);
@@ -339,17 +336,19 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
336
else if(!strcmp(name, "utc_offset"))
337
rpt->utc_offset = (int32_t)strtol(value, NULL, 0);
338
342
- else if(!strcmp(name, "hops"))
343
- rpt->hops = rpt->system_info->hops = (int16_t)strtol(value, NULL, 0);
339
+ else if(!strcmp(name, "hops")) {
340
+ rpt->hops = (int16_t)strtol(value, NULL, 0);
341
+ rrdhost_system_info_hops_set(rpt->system_info, rpt->hops);
342
+ }
343
344
else if(!strcmp(name, "ml_capable"))
346
- rpt->system_info->ml_capable = strtoul(value, NULL, 0);
345
+ rrdhost_system_info_ml_capable_set(rpt->system_info, str2i(value));
346
347
else if(!strcmp(name, "ml_enabled"))
349
- rpt->system_info->ml_enabled = strtoul(value, NULL, 0);
348
+ rrdhost_system_info_ml_enabled_set(rpt->system_info, str2i(value));
349
350
else if(!strcmp(name, "mc_version"))
352
- rpt->system_info->mc_version = strtoul(value, NULL, 0);
351
+ rrdhost_system_info_mc_version_set(rpt->system_info, str2i(value));
352
353
else if(!strcmp(name, "ver") && (rpt->capabilities & STREAM_CAP_INVALID))
354
rpt->capabilities = convert_stream_version_to_capabilities(strtoul(value, NULL, 0), NULL, false);
@@ -377,7 +376,7 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
376
else if(!strcmp(name, "NETDATA_PROTOCOL_VERSION") && (rpt->capabilities & STREAM_CAP_INVALID))
377
rpt->capabilities = convert_stream_version_to_capabilities(1, NULL, false);
378
380
- if (unlikely(rrdhost_set_system_info_variable(rpt->system_info, name, value))) {
379
+ if (unlikely(rrdhost_system_info_set_by_name(rpt->system_info, name, value))) {
380
nd_log_daemon(NDLP_NOTICE, "STREAM RCV '%s' [from [%s]:%s]: "
381
"request has parameter '%s' = '%s', which is not used."
382
, (rpt->hostname && *rpt->hostname) ? rpt->hostname : "-"
src/web/api/v1/api_v1_info.c
+2
-31
@@ -38,7 +38,7 @@ static inline void web_client_api_request_v1_info_mirrored_hosts_status(BUFFER *
38
buffer_json_add_array_item_object(wb);
39
40
buffer_json_member_add_string(wb, "hostname", rrdhost_hostname(host));
41
- buffer_json_member_add_uint64(wb, "hops", host->system_info ? host->system_info->hops : (host == localhost) ? 0 : 1);
41
+ buffer_json_member_add_uint64(wb, "hops", host->system_info ? rrdhost_system_info_hops(host->system_info) : (host == localhost) ? 0 : 1);
42
buffer_json_member_add_boolean(wb, "reachable", (host == localhost || !rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN)));
43
44
buffer_json_member_add_string(wb, "guid", host->machine_guid);
@@ -115,36 +115,7 @@ static int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
115
116
web_client_api_request_v1_info_summary_alarm_statuses(host, wb, "alarms");
117
118
- buffer_json_member_add_string_or_empty(wb, "os_name", host->system_info->host_os_name);
119
- buffer_json_member_add_string_or_empty(wb, "os_id", host->system_info->host_os_id);
120
- buffer_json_member_add_string_or_empty(wb, "os_id_like", host->system_info->host_os_id_like);
121
- buffer_json_member_add_string_or_empty(wb, "os_version", host->system_info->host_os_version);
122
- buffer_json_member_add_string_or_empty(wb, "os_version_id", host->system_info->host_os_version_id);
123
- buffer_json_member_add_string_or_empty(wb, "os_detection", host->system_info->host_os_detection);
124
- buffer_json_member_add_string_or_empty(wb, "cores_total", host->system_info->host_cores);
125
- buffer_json_member_add_string_or_empty(wb, "total_disk_space", host->system_info->host_disk_space);
126
- buffer_json_member_add_string_or_empty(wb, "cpu_freq", host->system_info->host_cpu_freq);
127
- buffer_json_member_add_string_or_empty(wb, "ram_total", host->system_info->host_ram_total);
128
-
129
- buffer_json_member_add_string_or_omit(wb, "container_os_name", host->system_info->container_os_name);
130
- buffer_json_member_add_string_or_omit(wb, "container_os_id", host->system_info->container_os_id);
131
- buffer_json_member_add_string_or_omit(wb, "container_os_id_like", host->system_info->container_os_id_like);
132
- buffer_json_member_add_string_or_omit(wb, "container_os_version", host->system_info->container_os_version);
133
- buffer_json_member_add_string_or_omit(wb, "container_os_version_id", host->system_info->container_os_version_id);
134
- buffer_json_member_add_string_or_omit(wb, "container_os_detection", host->system_info->container_os_detection);
135
- buffer_json_member_add_string_or_omit(wb, "is_k8s_node", host->system_info->is_k8s_node);
136
-
137
- buffer_json_member_add_string_or_empty(wb, "kernel_name", host->system_info->kernel_name);
138
- buffer_json_member_add_string_or_empty(wb, "kernel_version", host->system_info->kernel_version);
139
- buffer_json_member_add_string_or_empty(wb, "architecture", host->system_info->architecture);
140
- buffer_json_member_add_string_or_empty(wb, "virtualization", host->system_info->virtualization);
141
- buffer_json_member_add_string_or_empty(wb, "virt_detection", host->system_info->virt_detection);
142
- buffer_json_member_add_string_or_empty(wb, "container", host->system_info->container);
143
- buffer_json_member_add_string_or_empty(wb, "container_detection", host->system_info->container_detection);
144
-
145
- buffer_json_member_add_string_or_omit(wb, "cloud_provider_type", host->system_info->cloud_provider_type);
146
- buffer_json_member_add_string_or_omit(wb, "cloud_instance_type", host->system_info->cloud_instance_type);
147
- buffer_json_member_add_string_or_omit(wb, "cloud_instance_region", host->system_info->cloud_instance_region);
118
+ rrdhost_system_info_to_json_v1(wb, host->system_info);
119
120
host_labels2json(host, wb, "host_labels");
121
host_functions2json(host, wb);