From a2d7dede737947d7c6afa20a88e1f0c64e0eb96c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 10 Aug 2023 11:18:52 +0200 Subject: Merging upstream version 1.42.0. Signed-off-by: Daniel Baumann --- daemon/README.md | 2 +- daemon/anonymous-statistics.sh.in | 18 ++++++++++++++++++ daemon/buildinfo.c | 2 +- daemon/commands.c | 8 ++++---- daemon/daemon.c | 26 +++++++++++++++----------- daemon/daemon.h | 3 ++- daemon/main.c | 3 +++ daemon/static_threads.c | 9 +++++++++ daemon/system-info.sh | 2 +- 9 files changed, 54 insertions(+), 19 deletions(-) (limited to 'daemon') diff --git a/daemon/README.md b/daemon/README.md index 65ac105c6..3fb33e5c7 100644 --- a/daemon/README.md +++ b/daemon/README.md @@ -104,7 +104,7 @@ The command line options of the Netdata 1.10.0 version are the following: -W simple-pattern pattern string Check if string matches pattern and exit. - -W "claim -token=TOKEN -rooms=ROOM1,ROOM2 url=https://api.netdata.cloud" + -W "claim -token=TOKEN -rooms=ROOM1,ROOM2 url=https://app.netdata.cloud" Connect the agent to the workspace rooms pointed to by TOKEN and ROOM*. Signals netdata handles: diff --git a/daemon/anonymous-statistics.sh.in b/daemon/anonymous-statistics.sh.in index 32cbc71db..6b27dfea4 100755 --- a/daemon/anonymous-statistics.sh.in +++ b/daemon/anonymous-statistics.sh.in @@ -71,6 +71,23 @@ NETDATA_PREBUILT_DISTRO="${42}" [ -z "$NETDATA_REGISTRY_UNIQUE_ID" ] && NETDATA_REGISTRY_UNIQUE_ID="00000000-0000-0000-0000-000000000000" +KERNEL_NAME="$(uname -s)" +MD5_PATH="$(exec <&- 2>&-; which md5sum || command -v md5sum || type md5sum)" + +if [ "${KERNEL_NAME}" = Darwin ] && command -v ioreg >/dev/null 2>&1; then + SYSTEM_DISTINCT_ID="macos-$(ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }')" +elif [ -f /etc/machine-id ] && [ -n "$MD5_PATH" ]; then + SYSTEM_DISTINCT_ID="machine-$($MD5_PATH < /etc/machine-id | cut -f1 -d" ")" +elif [ -f /var/db/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then + SYSTEM_DISTINCT_ID="dbus-$($MD5_PATH < /var/db/dbus/machine-id | cut -f1 -d" ")" +elif [ -f /var/lib/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then + SYSTEM_DISTINCT_ID="dbus-$($MD5_PATH < /var/lib/dbus/machine-id | cut -f1 -d" ")" +elif command -v uuidgen > /dev/null 2>&1; then + SYSTEM_DISTINCT_ID="uuid-$(uuidgen | tr '[:upper:]' '[:lower:]')" +else + SYSTEM_DISTINCT_ID="null" +fi + # define body of request to be sent REQ_BODY="$(cat << EOF { @@ -105,6 +122,7 @@ REQ_BODY="$(cat << EOF "system_virt_detection": "${NETDATA_SYSTEM_VIRT_DETECTION}", "system_container": "${NETDATA_SYSTEM_CONTAINER}", "system_container_detection": "${NETDATA_SYSTEM_CONTAINER_DETECTION}", + "system_distinct_id": "${SYSTEM_DISTINCT_ID}", "container_os_name": "${NETDATA_CONTAINER_OS_NAME}", "container_os_id": "${NETDATA_CONTAINER_OS_ID}", "container_os_id_like": "${NETDATA_CONTAINER_OS_ID_LIKE}", diff --git a/daemon/buildinfo.c b/daemon/buildinfo.c index 56cde84fc..4bc1e72a4 100644 --- a/daemon/buildinfo.c +++ b/daemon/buildinfo.c @@ -1469,7 +1469,7 @@ void print_build_info_json(void) { populate_directories(); BUFFER *b = buffer_create(0, NULL); - buffer_json_initialize(b, "\"", "\"", 0, true, false); + buffer_json_initialize(b, "\"", "\"", 0, true, BUFFER_JSON_OPTIONS_DEFAULT); build_info_to_json_object(b); diff --git a/daemon/commands.c b/daemon/commands.c index 84298416e..a8afb5a00 100644 --- a/daemon/commands.c +++ b/daemon/commands.c @@ -407,7 +407,7 @@ static void pipe_write_cb(uv_write_t* req, int status) uv_close((uv_handle_t *)client, pipe_close_cb); --clients; buffer_free(client->data); - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); } static inline void add_char_to_command_reply(BUFFER *reply_string, unsigned *reply_string_size, char character) @@ -557,7 +557,7 @@ static void pipe_read_cb(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf if (nread < 0 && UV_EOF != nread) { uv_close((uv_handle_t *)client, pipe_close_cb); --clients; - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); } } @@ -593,7 +593,7 @@ static void connection_cb(uv_stream_t *server, int status) } ++clients; - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); /* Start parsing a new command */ cmd_ctx->command_string_size = 0; cmd_ctx->command_string[0] = '\0'; @@ -603,7 +603,7 @@ static void connection_cb(uv_stream_t *server, int status) netdata_log_error("uv_read_start(): %s", uv_strerror(ret)); uv_close((uv_handle_t *)client, pipe_close_cb); --clients; - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); return; } } diff --git a/daemon/daemon.c b/daemon/daemon.c index 0d1d17324..c7f0b51c6 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -4,11 +4,11 @@ #include char pidfile[FILENAME_MAX + 1] = ""; -char claimingdirectory[FILENAME_MAX + 1]; -char exepath[FILENAME_MAX + 1]; +char claiming_directory[FILENAME_MAX + 1]; +char netdata_exe_path[FILENAME_MAX + 1]; +char netdata_exe_file[FILENAME_MAX + 1]; -void get_netdata_execution_path(void) -{ +void get_netdata_execution_path(void) { int ret; size_t exepath_size = 0; struct passwd *passwd = NULL; @@ -17,14 +17,18 @@ void get_netdata_execution_path(void) passwd = getpwuid(getuid()); user = (passwd && passwd->pw_name) ? passwd->pw_name : ""; - exepath_size = sizeof(exepath) - 1; - ret = uv_exepath(exepath, &exepath_size); + exepath_size = sizeof(netdata_exe_file) - 1; + ret = uv_exepath(netdata_exe_file, &exepath_size); if (0 != ret) { - netdata_log_error("uv_exepath(\"%s\", %u) (user: %s) failed (%s).", exepath, (unsigned)exepath_size, user, - uv_strerror(ret)); + netdata_log_error("uv_exepath(\"%s\", %u) (user: %s) failed (%s).", netdata_exe_file, (unsigned)exepath_size, user, + uv_strerror(ret)); fatal("Cannot start netdata without getting execution path."); } - exepath[exepath_size] = '\0'; + + netdata_exe_file[exepath_size] = '\0'; + + strcpy(netdata_exe_path, netdata_exe_file); + dirname(netdata_exe_path); } static void chown_open_file(int fd, uid_t uid, gid_t gid) { @@ -99,7 +103,7 @@ void prepare_required_directories(uid_t uid, gid_t gid) { change_dir_ownership(netdata_configured_varlib_dir, uid, gid, false); change_dir_ownership(netdata_configured_lock_dir, uid, gid, false); change_dir_ownership(netdata_configured_log_dir, uid, gid, false); - change_dir_ownership(claimingdirectory, uid, gid, false); + change_dir_ownership(claiming_directory, uid, gid, false); char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir); @@ -516,7 +520,7 @@ int become_daemon(int dont_fork, const char *user) sched_setscheduler_set(); // Set claiming directory based on user config directory with correct ownership - snprintfz(claimingdirectory, FILENAME_MAX, "%s/cloud.d", netdata_configured_varlib_dir); + snprintfz(claiming_directory, FILENAME_MAX, "%s/cloud.d", netdata_configured_varlib_dir); if(user && *user) { if(become_user(user, pidfd) != 0) { diff --git a/daemon/daemon.h b/daemon/daemon.h index 2a8a58ec6..7c4c2ce7e 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -13,6 +13,7 @@ void send_statistics(const char *action, const char *action_result, const char * void get_netdata_execution_path(void); extern char pidfile[]; -extern char exepath[]; +extern char netdata_exe_file[]; +extern char netdata_exe_path[]; #endif /* NETDATA_DAEMON_H */ diff --git a/daemon/main.c b/daemon/main.c index 13644d4b6..6ddf57aa1 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1332,6 +1332,7 @@ int mrg_unittest(void); int julytest(void); int pluginsd_parser_unittest(void); void replication_initialize(void); +void bearer_tokens_init(void); int main(int argc, char **argv) { // initialize the system clocks @@ -1937,6 +1938,8 @@ int main(int argc, char **argv) { signals_block(); signals_init(); // setup the signals we want to use + dyn_conf_init(); + // -------------------------------------------------------------------- // check which threads are enabled and initialize them diff --git a/daemon/static_threads.c b/daemon/static_threads.c index 4ee2a4668..830b854e6 100644 --- a/daemon/static_threads.c +++ b/daemon/static_threads.c @@ -195,6 +195,15 @@ const struct netdata_static_thread static_threads_common[] = { .init_routine = NULL, .start_routine = profile_main }, + { + .name = "DYNCFG", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = dyncfg_main + }, // terminator { diff --git a/daemon/system-info.sh b/daemon/system-info.sh index 43f761c2d..2a3ba7d76 100755 --- a/daemon/system-info.sh +++ b/daemon/system-info.sh @@ -313,7 +313,7 @@ elif [ -r /proc/cpuinfo ]; then if (echo "${CPU_INFO_SOURCE}" | grep -qv procfs); then CPU_INFO_SOURCE="${CPU_INFO_SOURCE} procfs" fi - value=$(grep "cpu MHz" /proc/cpuinfo 2>/dev/null | grep -o "[0-9]*" | head -n 1 | awk '{print int($0*1000000)}') + value=$(grep "cpu MHz" /proc/cpuinfo 2>/dev/null | grep -o "[0-9]*" | head -n 1 | awk '{printf "%0.f",int($0*1000000)}') [ -n "$value" ] && CPU_FREQ="$value" fi -- cgit v1.2.3