summaryrefslogtreecommitdiffstats
path: root/daemon/anonymous-statistics.sh.in
blob: f49d19d09d8aa23b89480900d0c2ff0d46dc2e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env sh

# Valid actions:

# - FATAL       - netdata exited due to a fatal condition
#      ACTION_RESULT  -- program name and thread tag
#      ACTION_DATA    -- fmt, args passed to fatal
# - START       - netdata started
#      ACTION_DATA     -- nan
# - EXIT        - installation action
#      ACTION_DATA     -- ret value of

ACTION="${1}"
ACTION_RESULT="${2}"
ACTION_DATA="${3}"
ACTION_DATA=$(echo "${ACTION_DATA}" | tr '"' "'")

# -------------------------------------------------------------------------------------------------
# check opt-out

if [ -f "@configdir_POST@/.opt-out-from-anonymous-statistics" ] || [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] || [ -n "$DO_NOT_TRACK" ]; then
  exit 0
fi

# -------------------------------------------------------------------------------------------------
# Get the extra variables

NETDATA_CONFIG_STREAM_ENABLED="${4}"
NETDATA_CONFIG_MEMORY_MODE="${5}"
NETDATA_CONFIG_EXPORTING_ENABLED="${6}"
NETDATA_EXPORTING_CONNECTORS="${7}"
NETDATA_ALLMETRICS_PROMETHEUS_USED="${8}"
NETDATA_ALLMETRICS_SHELL_USED="${9}"
NETDATA_ALLMETRICS_JSON_USED="${10}"
NETDATA_DASHBOARD_USED="${11}"
NETDATA_COLLECTORS="${12}"
NETDATA_COLLECTORS_COUNT="${13}"
NETDATA_BUILDINFO="${14}"
NETDATA_CONFIG_PAGE_CACHE_SIZE="${15}"
NETDATA_CONFIG_MULTIDB_DISK_QUOTA="${16}"
NETDATA_CONFIG_HTTPS_ENABLED="${17}"
NETDATA_CONFIG_WEB_ENABLED="${18}"
NETDATA_CONFIG_RELEASE_CHANNEL="${19}"
NETDATA_MIRRORED_HOST_COUNT="${20}"
NETDATA_MIRRORED_HOSTS_REACHABLE="${21}"
NETDATA_MIRRORED_HOSTS_UNREACHABLE="${22}"
NETDATA_NOTIFICATION_METHODS="${23}"
NETDATA_ALARMS_NORMAL="${24}"
NETDATA_ALARMS_WARNING="${25}"
NETDATA_ALARMS_CRITICAL="${26}"
NETDATA_CHARTS_COUNT="${27}"
NETDATA_METRICS_COUNT="${28}"
NETDATA_CONFIG_IS_PARENT="${29}"
NETDATA_CONFIG_HOSTS_AVAILABLE="${30}"
NETDATA_HOST_CLOUD_AVAILABLE="${31}"
NETDATA_HOST_ACLK_AVAILABLE="${32}"
NETDATA_HOST_ACLK_IMPLEMENTATION="${33}"
NETDATA_HOST_AGENT_CLAIMED="${34}"
NETDATA_HOST_CLOUD_ENABLED="${35}"
NETDATA_CONFIG_HTTPS_AVAILABLE="${36}"
NETDATA_INSTALL_TYPE="${37}"
NETDATA_IS_PRIVATE_REGISTRY="${38}"
NETDATA_USE_PRIVATE_REGISTRY="${39}"
NETDATA_CONFIG_OOM_SCORE="${40}"
NETDATA_PREBUILT_DISTRO="${41}"


# define body of request to be sent
REQ_BODY="$(cat << EOF
{
    "api_key": "mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y",
    "event": "${ACTION} ${ACTION_RESULT}",
    "properties": {
        "distinct_id": "${NETDATA_REGISTRY_UNIQUE_ID}",
        "\$current_url": "agent backend",
        "\$pathname": "netdata-backend",
        "\$host": "backend.netdata.io",
        "\$ip": "127.0.0.1",
        "event_source": "agent backend",
        "action": "${ACTION}",
        "action_result": "${ACTION_RESULT}",
        "action_data": "${ACTION_DATA}",
        "netdata_machine_guid": "${NETDATA_REGISTRY_UNIQUE_ID}",
        "netdata_version": "${NETDATA_VERSION}",
        "netdata_buildinfo": ${NETDATA_BUILDINFO},
        "netdata_release_channel": ${NETDATA_CONFIG_RELEASE_CHANNEL},
        "netdata_install_type": ${NETDATA_INSTALL_TYPE},
        "netdata_prebuilt_distro": ${NETDATA_PREBUILT_DISTRO},
        "host_os_name": "${NETDATA_HOST_OS_NAME}",
        "host_os_id": "${NETDATA_HOST_OS_ID}",
        "host_os_id_like": "${NETDATA_HOST_OS_ID_LIKE}",
        "host_os_version": "${NETDATA_HOST_OS_VERSION}",
        "host_os_version_id": "${NETDATA_HOST_OS_VERSION_ID}",
        "host_os_detection": "${NETDATA_HOST_OS_DETECTION}",
        "host_is_k8s_node": "${NETDATA_HOST_IS_K8S_NODE}",
        "system_kernel_name": "${NETDATA_SYSTEM_KERNEL_NAME}",
        "system_kernel_version": "${NETDATA_SYSTEM_KERNEL_VERSION}",
        "system_architecture": "${NETDATA_SYSTEM_ARCHITECTURE}",
        "system_virtualization": "${NETDATA_SYSTEM_VIRTUALIZATION}",
        "system_virt_detection": "${NETDATA_SYSTEM_VIRT_DETECTION}",
        "system_container": "${NETDATA_SYSTEM_CONTAINER}",
        "system_container_detection": "${NETDATA_SYSTEM_CONTAINER_DETECTION}",
        "container_os_name": "${NETDATA_CONTAINER_OS_NAME}",
        "container_os_id": "${NETDATA_CONTAINER_OS_ID}",
        "container_os_id_like": "${NETDATA_CONTAINER_OS_ID_LIKE}",
        "container_os_version": "${NETDATA_CONTAINER_OS_VERSION}",
        "container_os_version_id": "${NETDATA_CONTAINER_OS_VERSION_ID}",
        "container_os_detection": "${NETDATA_CONTAINER_OS_DETECTION}",
        "container_is_official_image": ${NETDATA_CONTAINER_IS_OFFICIAL_IMAGE},
        "system_cpu_detection": "${NETDATA_SYSTEM_CPU_DETECTION}",
        "system_cpu_freq": "${NETDATA_SYSTEM_CPU_FREQ}",
        "system_cpu_logical_cpu_count": "${NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT}",
        "system_cpu_model": "${NETDATA_SYSTEM_CPU_MODEL}",
        "system_cpu_vendor": "${NETDATA_SYSTEM_CPU_VENDOR}",
        "system_disk_detection": "${NETDATA_SYSTEM_DISK_DETECTION}",
        "system_ram_detection": "${NETDATA_SYSTEM_RAM_DETECTION}",
        "system_total_disk_size": "${NETDATA_SYSTEM_TOTAL_DISK_SIZE}",
        "system_total_ram": "${NETDATA_SYSTEM_TOTAL_RAM}",
        "config_stream_enabled": ${NETDATA_CONFIG_STREAM_ENABLED},
        "config_memory_mode": ${NETDATA_CONFIG_MEMORY_MODE},
        "config_page_cache_size": ${NETDATA_CONFIG_PAGE_CACHE_SIZE},
        "config_multidb_disk_quota": ${NETDATA_CONFIG_MULTIDB_DISK_QUOTA},
        "config_https_enabled": ${NETDATA_CONFIG_HTTPS_ENABLED},
        "config_https_available": ${NETDATA_CONFIG_HTTPS_AVAILABLE},
        "config_web_enabled": ${NETDATA_CONFIG_WEB_ENABLED},
        "config_exporting_enabled": ${NETDATA_CONFIG_EXPORTING_ENABLED},
        "config_is_parent": ${NETDATA_CONFIG_IS_PARENT},
        "config_is_private_registry": ${NETDATA_IS_PRIVATE_REGISTRY},
        "config_private_registry_used": ${NETDATA_USE_PRIVATE_REGISTRY},
        "config_hosts_available": ${NETDATA_CONFIG_HOSTS_AVAILABLE},
        "config_oom_score": ${NETDATA_CONFIG_OOM_SCORE},
        "alarms_normal": ${NETDATA_ALARMS_NORMAL},
        "alarms_warning": ${NETDATA_ALARMS_WARNING},
        "alarms_critical": ${NETDATA_ALARMS_CRITICAL},
        "host_charts_count": ${NETDATA_CHARTS_COUNT},
        "host_metrics_count": ${NETDATA_METRICS_COUNT},
        "host_collectors":[
            ${NETDATA_COLLECTORS}
        ],
        "host_collectors_count": ${NETDATA_COLLECTORS_COUNT},
        "host_notification_methods": ${NETDATA_NOTIFICATION_METHODS},
        "host_allmetrics_prometheus_used": ${NETDATA_ALLMETRICS_PROMETHEUS_USED},
        "host_allmetrics_shell_used": ${NETDATA_ALLMETRICS_SHELL_USED},
        "host_allmetrics_json_used": ${NETDATA_ALLMETRICS_JSON_USED},
        "host_dashboard_used": ${NETDATA_DASHBOARD_USED},
        "host_cloud_available": ${NETDATA_HOST_CLOUD_AVAILABLE},
        "host_cloud_enabled": ${NETDATA_HOST_CLOUD_ENABLED},
        "host_agent_claimed": ${NETDATA_HOST_AGENT_CLAIMED},
        "host_aclk_available": ${NETDATA_HOST_ACLK_AVAILABLE},
        "host_aclk_implementation": ${NETDATA_HOST_ACLK_IMPLEMENTATION},
        "mirrored_host_count": ${NETDATA_MIRRORED_HOST_COUNT},
        "mirrored_hosts_reachable": ${NETDATA_MIRRORED_HOSTS_REACHABLE},
        "mirrored_hosts_unreachable": ${NETDATA_MIRRORED_HOSTS_UNREACHABLE},
        "exporting_connectors": ${NETDATA_EXPORTING_CONNECTORS}
  }
}
EOF
)"

# send the anonymous statistics to the Netdata PostHog
if [ -n "$(command -v curl 2> /dev/null)" ]; then
  curl --silent -o /dev/null --write-out '%{http_code}' -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" https://posthog.netdata.cloud/capture/
else
  wget -q -O - --no-check-certificate \
  --server-response \
  --method POST \
  --timeout=1 \
  --header 'Content-Type: application/json' \
  --body-data "${REQ_BODY}" \
   'https://posthog.netdata.cloud/capture/' 2>&1 | awk '/^  HTTP/{print $2}'
fi