@cryptotaxi247 / netdata-1 / commits / 46a0dd964

status has install type (#19722)

* status has install type; fixed bug with multiple json version in the status file * fix the wrong calculation of libuv threads

Costa Tsaousis committed Feb 26, 2025 at 22:00 UTC 46a0dd964f177e80ba811a044f65d88db63bbe7e
4 files changed +22 -4
src/daemon/buildinfo.h
+2
@@ -15,4 +15,6 @@ void get_install_type(struct rrdhost_system_info *system_info);
15
16 void build_info_to_json_object(BUFFER *b);
17
18 +void get_install_type_internal(char **install_type, char **prebuilt_arch, char **prebuilt_dist);
19 +
20 #endif // NETDATA_BUILDINFO_H
src/daemon/config/netdata-conf-global.c
+4 -1
@@ -76,9 +76,12 @@ void netdata_conf_glibc_malloc_initialize(size_t wanted_arenas, size_t trim_thre
76 }
77
78 void libuv_initialize(void) {
79 + libuv_worker_threads = (int)netdata_conf_cpus() * 6;
80 + libuv_worker_threads = MIN(MAX_LIBUV_WORKER_THREADS, MAX(MIN_LIBUV_WORKER_THREADS, libuv_worker_threads));
81 +
82 libuv_worker_threads = (int)inicfg_get_number_range(
83 &netdata_config, CONFIG_SECTION_GLOBAL, "libuv worker threads",
81 - (int)netdata_conf_cpus() * 6, MIN_LIBUV_WORKER_THREADS, MAX_LIBUV_WORKER_THREADS);
84 + libuv_worker_threads, MIN_LIBUV_WORKER_THREADS, MAX_LIBUV_WORKER_THREADS);
85
86 char buf[20 + 1];
87 snprintfz(buf, sizeof(buf) - 1, "%d", libuv_worker_threads);
src/daemon/daemon-status-file.c
+15 -3
@@ -2,6 +2,7 @@
2
3 #include "common.h"
4 #include "daemon-status-file.h"
5 +#include "buildinfo.h"
6
7 #include <curl/curl.h>
8 #include <openssl/evp.h>
@@ -11,7 +12,6 @@
12 #define STATUS_FILE_VERSION 3
13
14 #define STATUS_FILENAME "status-netdata.json"
14 -#define STATUS_FILENAME_TMP "status-netdata.json.tmp"
15
16 ENUM_STR_MAP_DEFINE(DAEMON_STATUS) = {
17 { DAEMON_STATUS_NONE, "none"},
@@ -86,6 +86,8 @@ static void daemon_status_file_to_json(BUFFER *wb, DAEMON_STATUS_FILE *ds) {
86 buffer_json_member_add_string(wb, "ND_status", DAEMON_STATUS_2str(ds->status)); // custom
87 EXIT_REASON_2json(wb, "ND_exit_reason", ds->exit_reason); // custom
88
89 + buffer_json_member_add_string_or_empty(wb, "ND_install_type", ds->install_type); // custom
90 +
91 buffer_json_member_add_object(wb, "ND_timings"); // custom
92 {
93 buffer_json_member_add_time_t(wb, "init", ds->timings.init);
@@ -195,6 +197,7 @@ static bool daemon_status_file_from_json(json_object *jobj, void *data, BUFFER *
197 JSONC_PARSE_ARRAY_OF_TXT2BITMAP_OR_ERROR_AND_RETURN(jobj, path, "ND_exit_reason", EXIT_REASON_2id_one, ds->exit_reason, error, required_v1);
198 JSONC_PARSE_TXT2UUID_OR_ERROR_AND_RETURN(jobj, path, "ND_node_id", ds->node_id.uuid, error, required_v1);
199 JSONC_PARSE_TXT2UUID_OR_ERROR_AND_RETURN(jobj, path, "ND_claim_id", ds->claim_id.uuid, error, required_v1);
200 + JSONC_PARSE_TXT2STRDUPZ_OR_ERROR_AND_RETURN(jobj, path, "ND_install_type", ds->install_type, error, required_v3);
201
202 JSONC_PARSE_SUBOBJECT(jobj, path, "ND_timings", error, required_v1, {
203 JSONC_PARSE_UINT64_OR_ERROR_AND_RETURN(jobj, path, "init", ds->timings.init, error, required_v1);
@@ -353,6 +356,14 @@ static void daemon_status_file_refresh(DAEMON_STATUS status) {
356 session_status.dedup.hash = last_session_status.dedup.hash;
357 }
358
359 + if(!session_status.install_type) {
360 + char *install_type = NULL, *prebuilt_arch = NULL, *prebuilt_dist = NULL;
361 + get_install_type_internal(&install_type, &prebuilt_arch, &prebuilt_dist);
362 + freez(prebuilt_arch);
363 + freez(prebuilt_dist);
364 + session_status.install_type = install_type;
365 + }
366 +
367 get_daemon_status_fields_from_system_info(&session_status);
368
369 session_status.exit_reason = exit_initiated;
@@ -466,7 +477,7 @@ static bool save_status_file(const char *directory, const char *content, size_t
477 char temp_filename[FILENAME_MAX];
478
479 snprintfz(filename, sizeof(filename), "%s/%s", directory, STATUS_FILENAME);
469 - snprintfz(temp_filename, sizeof(temp_filename), "%s/%s", directory, STATUS_FILENAME_TMP);
480 + snprintfz(temp_filename, sizeof(temp_filename), "%s/%s-%08x", directory, STATUS_FILENAME, (unsigned)gettid_cached());
481
482 FILE *fp = fopen(temp_filename, "w");
483 if (!fp)
@@ -502,6 +513,7 @@ static void daemon_status_file_save(DAEMON_STATUS_FILE *ds) {
513 if (!wb)
514 wb = buffer_create(16384, NULL);
515
516 + buffer_flush(wb);
517 buffer_json_initialize(wb, "\"", "\"", 0, true, BUFFER_JSON_OPTIONS_DEFAULT);
518 daemon_status_file_to_json(wb, ds);
519 buffer_json_finalize(wb);
@@ -519,7 +531,7 @@ static void daemon_status_file_save(DAEMON_STATUS_FILE *ds) {
531
532 // Try each fallback directory until successful
533 for(size_t i = 0; i < _countof(status_file_fallbacks); i++) {
522 - if(save_status_file(status_file_fallbacks[i], content, content_size)) {
534 + if (save_status_file(status_file_fallbacks[i], content, content_size)) {
535 nd_log(NDLS_DAEMON, NDLP_DEBUG, "Saved status file in fallback %s", status_file_fallbacks[i]);
536 saved = true;
537 break;
src/daemon/daemon-status-file.h
+1
@@ -49,6 +49,7 @@ typedef struct daemon_status_file {
49 OS_SYSTEM_MEMORY memory;
50 OS_SYSTEM_DISK_SPACE var_cache;
51
52 + const char *install_type;
53 const char *architecture; // ECS: host.architecture
54 const char *virtualization;
55 const char *container;