0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-26 13:54:48 +00:00

Add a machine distinct id to analytics ()

* add a system distinct id to analytics
This commit is contained in:
Emmanuel Vasilakis 2023-07-24 21:00:26 +03:00 committed by GitHub
parent 7a0841f7a3
commit d759ebbb7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View file

@ -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}",

View file

@ -257,14 +257,16 @@ telemetry_event() {
TOTAL_RAM="$((TOTAL_RAM * 1024))"
fi
MD5_PATH="$(exec <&- 2>&-; which md5sum || command -v md5sum || type md5sum)"
if [ "${KERNEL_NAME}" = Darwin ] && command -v ioreg >/dev/null 2>&1; then
DISTINCT_ID="macos-$(ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }')"
elif [ -f /etc/machine-id ]; then
DISTINCT_ID="machine-$(cat /etc/machine-id)"
elif [ -f /var/db/dbus/machine-id ]; then
DISTINCT_ID="dbus-$(cat /var/db/dbus/machine-id)"
elif [ -f /var/lib/dbus/machine-id ]; then
DISTINCT_ID="dbus-$(cat /var/lib/dbus/machine-id)"
elif [ -f /etc/machine-id ] && [ -n "$MD5_PATH" ]; then
DISTINCT_ID="machine-$($MD5_PATH < /etc/machine-id | cut -f1 -d" ")"
elif [ -f /var/db/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then
DISTINCT_ID="dbus-$($MD5_PATH < /var/db/dbus/machine-id | cut -f1 -d" ")"
elif [ -f /var/lib/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then
DISTINCT_ID="dbus-$($MD5_PATH < /var/lib/dbus/machine-id | cut -f1 -d" ")"
elif command -v uuidgen > /dev/null 2>&1; then
DISTINCT_ID="uuid-$(uuidgen | tr '[:upper:]' '[:lower:]')"
else
@ -300,7 +302,8 @@ telemetry_event() {
"system_kernel_name": "${KERNEL_NAME}",
"system_kernel_version": "$(uname -r)",
"system_architecture": "$(uname -m)",
"system_total_ram": "${TOTAL_RAM:-unknown}"
"system_total_ram": "${TOTAL_RAM:-unknown}",
"system_distinct_id": "${DISTINCT_ID}"
}
}
EOF