Add node message support for ACLK new architecture (#11514)
* node info function * Code cleanup * Remove unnecessary strdupz / freez functions * Fix complication error if ACLK_NG is not available
Stelios Fragkakis committed
Sep 20, 2021 at 18:51 UTC
cb405deec824848fada38d363cfafa557f6727a4
5 files changed
+74
-6
CMakeLists.txt
+2
@@ -633,6 +633,8 @@ set(RRD_PLUGIN_FILES
633
database/sqlite/sqlite_aclk.h
634
database/sqlite/sqlite_health.c
635
database/sqlite/sqlite_health.h
636
+ database/sqlite/sqlite_aclk_node.c
637
+ database/sqlite/sqlite_aclk_node.h
638
database/sqlite/sqlite3.c
639
database/sqlite/sqlite3.h
640
database/engine/rrdengine.c
Makefile.am
+2
@@ -413,6 +413,8 @@ RRD_PLUGIN_FILES = \
413
database/sqlite/sqlite_aclk.h \
414
database/sqlite/sqlite_health.c \
415
database/sqlite/sqlite_health.h \
416
+ database/sqlite/sqlite_aclk_node.c \
417
+ database/sqlite/sqlite_aclk_node.h \
418
database/sqlite/sqlite3.c \
419
database/sqlite/sqlite3.h \
420
$(NULL)
database/sqlite/sqlite_aclk.c
+2
-6
@@ -6,7 +6,7 @@
6
// TODO: To be added
7
//#include "sqlite_aclk_chart.h"
8
//#include "sqlite_aclk_alert.h"
9
-//#include "sqlite_aclk_node.h"
9
+#include "sqlite_aclk_node.h"
10
11
const char *aclk_sync_config[] = {
12
NULL,
@@ -412,13 +412,9 @@ void aclk_database_worker(void *arg)
412
break;
413
414
// NODE OPERATIONS
415
- case ACLK_DATABASE_RESET_NODE:
416
- debug(D_ACLK_SYNC,"Resetting the node instance id of %s", (char *) cmd.data);
417
-// aclk_reset_node_event(wc, cmd);
418
- break;
415
case ACLK_DATABASE_NODE_INFO:
416
debug(D_ACLK_SYNC,"Sending node info for %s", wc->uuid_str);
421
-// sql_build_node_info(wc, cmd);
417
+ sql_build_node_info(wc, cmd);
418
break;
419
case ACLK_DATABASE_UPD_STATS:
420
// sql_update_metric_statistics(wc, cmd);
database/sqlite/sqlite_aclk_node.c
new
+61
@@ -0,0 +1,61 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#include "sqlite_functions.h"
4
+#include "sqlite_aclk_node.h"
5
+
6
+#ifdef ACLK_NG
7
+#include "../../aclk/aclk_charts_api.h"
8
+#endif
9
+
10
+void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd)
11
+{
12
+ UNUSED(cmd);
13
+
14
+#ifdef ACLK_NG
15
+ struct update_node_info node_info;
16
+
17
+ rrd_wrlock();
18
+ node_info.node_id = wc->node_id;
19
+ node_info.claim_id = is_agent_claimed();
20
+ node_info.machine_guid = wc->host_guid;
21
+ node_info.child = (wc->host != localhost);
22
+ now_realtime_timeval(&node_info.updated_at);
23
+
24
+ RRDHOST *host = wc->host;
25
+
26
+ node_info.data.name = host->hostname;
27
+ node_info.data.os = (char *) host->os;
28
+ node_info.data.os_name = host->system_info->host_os_name;
29
+ node_info.data.os_version = host->system_info->host_os_version;
30
+ node_info.data.kernel_name = host->system_info->kernel_name;
31
+ node_info.data.kernel_version = host->system_info->kernel_version;
32
+ node_info.data.architecture = host->system_info->architecture;
33
+ node_info.data.cpus = str2uint32_t(host->system_info->host_cores);
34
+ node_info.data.cpu_frequency = host->system_info->host_cpu_freq;
35
+ node_info.data.memory = host->system_info->host_ram_total;
36
+ node_info.data.disk_space = host->system_info->host_disk_space;
37
+ node_info.data.version = VERSION;
38
+ node_info.data.release_channel = "nightly";
39
+ node_info.data.timezone = (char *) host->abbrev_timezone;
40
+ node_info.data.virtualization_type = host->system_info->virtualization;
41
+ node_info.data.container_type = host->system_info->container;
42
+ node_info.data.custom_info = config_get(CONFIG_SECTION_WEB, "custom dashboard_info.js", "");
43
+ node_info.data.services = NULL; // char **
44
+ node_info.data.service_count = 0;
45
+ node_info.data.machine_guid = wc->host_guid;
46
+
47
+ struct label_index *labels = &host->labels;
48
+ netdata_rwlock_wrlock(&labels->labels_rwlock);
49
+ node_info.data.host_labels_head = labels->head;
50
+
51
+ aclk_update_node_info(&node_info);
52
+
53
+ netdata_rwlock_unlock(&labels->labels_rwlock);
54
+ rrd_unlock();
55
+ freez(node_info.claim_id);
56
+#else
57
+ UNUSED(wc);
58
+#endif
59
+
60
+ return;
61
+}
database/sqlite/sqlite_aclk_node.h
new
+7
@@ -0,0 +1,7 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#ifndef NETDATA_SQLITE_ACLK_NODE_H
4
+#define NETDATA_SQLITE_ACLK_NODE_H
5
+
6
+void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
7
+#endif //NETDATA_SQLITE_ACLK_NODE_H