@cryptotaxi247 / netdata-1 / commits / 10b745cba

add `_is_k8s_node` label to the host labels (#10501)

* auto format system-info.sh * detect whether the node is k8s node in system-info.sh * fix unmae=>uname * add_is_k8s_node_to_host_labels: Add new variable to structure * add_is_k8s_node_to_host_labels: Add is_k8_node to labels * add_is_k8s_node_to_host_labels: Add is_k8_node inside endpoint * add_is_k8s_node_to_host_labels: Add data to swagge file * change yes/no to true/false * Update web/api/netdata-swagger.json * add_is_k8s_node_to_host_labels: Add anonymous statistic * add_is_k8s_node_to_host_labels: Add information to using-host-labels.md * add_is_k8s_node_to_host_labels: Add variable to stream * add_is_k8s_node_to_host_labels: Change swagger.yaml * add_is_k8s_node_to_host_labels: Adding missing documentation * add_is_k8s_node_to_host_labels: rename variable * add_is_k8s_node_to_host_labels: Rename lables to match variable names * add_is_k8s_node_to_host_labels: Add to wget * add_is_k8s_node_to_host_labels: Add content to swagger files * add_is_k8s_node_to_host_labels: update both swagger files * add_is_k8s_node_to_host_labels: fix wrong exportation Co-authored-by: Thiago Marques <thiagoftsm@gmail.com>

Ilya Mashchenko committed Jan 18, 2021 at 15:44 UTC 10b745cba808ed2069ae51c23d75c02cf3ca3f65
9 files changed +297 -259
daemon/anonymous-statistics.sh.in
+2
@@ -63,6 +63,7 @@ if [ -n "$(command -v curl 2> /dev/null)" ]; then
63 --data-urlencode "cd17=${NETDATA_CONTAINER_OS_VERSION}" \
64 --data-urlencode "cd18=${NETDATA_CONTAINER_OS_VERSION_ID}" \
65 --data-urlencode "cd19=${NETDATA_CONTAINER_OS_DETECTION}" \
66 + --data-urlencode "cd20=${NETDATA_HOST_IS_K8S_NODE}" \
67 "https://www.google-analytics.com/collect" > /dev/null 2>&1
68 else
69 wget -q -O - --timeout=1 "https://www.google-analytics.com/collect?\
@@ -98,5 +99,6 @@ else
99 &cd17=${NETDATA_CONTAINER_OS_VERSION} \
100 &cd18=${NETDATA_CONTAINER_OS_VERSION_ID} \
101 &cd19=${NETDATA_CONTAINER_OS_DETECTION} \
102 +&cd20=${NETDATA_HOST_IS_K8S_NODE} \
103 " > /dev/null 2>&1
104 fi
daemon/system-info.sh
+268 -257
@@ -11,32 +11,32 @@ ARCHITECTURE="$(uname -m)"
11 # detect the virtualization
12
13 if [ -z "${VIRTUALIZATION}" ]; then
14 - VIRTUALIZATION="unknown"
15 - VIRT_DETECTION="none"
16 -
17 - if [ -n "$(command -v systemd-detect-virt 2>/dev/null)" ]; then
18 - VIRTUALIZATION="$(systemd-detect-virt -v)"
19 - VIRT_DETECTION="systemd-detect-virt"
20 - CONTAINER="$(systemd-detect-virt -c)"
21 - CONT_DETECTION="systemd-detect-virt"
14 + VIRTUALIZATION="unknown"
15 + VIRT_DETECTION="none"
16 +
17 + if [ -n "$(command -v systemd-detect-virt 2> /dev/null)" ]; then
18 + VIRTUALIZATION="$(systemd-detect-virt -v)"
19 + VIRT_DETECTION="systemd-detect-virt"
20 + CONTAINER="$(systemd-detect-virt -c)"
21 + CONT_DETECTION="systemd-detect-virt"
22 + else
23 + if grep -q "^flags.*hypervisor" /proc/cpuinfo 2> /dev/null; then
24 + VIRTUALIZATION="hypervisor"
25 + VIRT_DETECTION="/proc/cpuinfo"
26 + elif [ -n "$(command -v dmidecode)" ] && dmidecode -s system-product-name 2> /dev/null | grep -q "VMware\|Virtual\|KVM\|Bochs"; then
27 + VIRTUALIZATION="$(dmidecode -s system-product-name)"
28 + VIRT_DETECTION="dmidecode"
29 else
23 - if grep -q "^flags.*hypervisor" /proc/cpuinfo 2>/dev/null; then
24 - VIRTUALIZATION="hypervisor"
25 - VIRT_DETECTION="/proc/cpuinfo"
26 - elif [ -n "$(command -v dmidecode)" ] && dmidecode -s system-product-name 2>/dev/null | grep -q "VMware\|Virtual\|KVM\|Bochs"; then
27 - VIRTUALIZATION="$(dmidecode -s system-product-name)"
28 - VIRT_DETECTION="dmidecode"
29 - else
30 - VIRTUALIZATION="none"
31 - fi
32 - fi
33 - if [ -z "${VIRTUALIZATION}" ]; then
34 - # Output from the command is outside of spec
35 - VIRTUALIZATION="unknown"
30 + VIRTUALIZATION="none"
31 fi
32 + fi
33 + if [ -z "${VIRTUALIZATION}" ]; then
34 + # Output from the command is outside of spec
35 + VIRTUALIZATION="unknown"
36 + fi
37 else
38 - # Passed from outside - probably in docker run
39 - VIRT_DETECTION="provided"
38 + # Passed from outside - probably in docker run
39 + VIRT_DETECTION="provided"
40 fi
41
42 # -------------------------------------------------------------------------------------------------
@@ -46,33 +46,33 @@ CONTAINER="unknown"
46 CONT_DETECTION="none"
47
48 if [ "${CONTAINER}" = "unknown" ]; then
49 - if [ -f /proc/1/sched ] ; then
50 - IFS='(, ' read -r process _ </proc/1/sched
51 - if [ "${process}" = "netdata" ]; then
52 - CONTAINER="container"
53 - CONT_DETECTION="process"
54 - fi
55 - fi
56 - # ubuntu and debian supply /bin/running-in-container
57 - # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
58 - if /bin/running-in-container >/dev/null 2>&1; then
59 - CONTAINER="container"
60 - CONT_DETECTION="/bin/running-in-container"
61 - fi
62 -
63 - # lxc sets environment variable 'container'
64 - #shellcheck disable=SC2154
65 - if [ -n "${container}" ]; then
66 - CONTAINER="lxc"
67 - CONT_DETECTION="containerenv"
68 - fi
69 -
70 - # docker creates /.dockerenv
71 - # http://stackoverflow.com/a/25518345
72 - if [ -f "/.dockerenv" ]; then
73 - CONTAINER="docker"
74 - CONT_DETECTION="dockerenv"
75 - fi
49 + if [ -f /proc/1/sched ]; then
50 + IFS='(, ' read -r process _ < /proc/1/sched
51 + if [ "${process}" = "netdata" ]; then
52 + CONTAINER="container"
53 + CONT_DETECTION="process"
54 + fi
55 + fi
56 + # ubuntu and debian supply /bin/running-in-container
57 + # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
58 + if /bin/running-in-container > /dev/null 2>&1; then
59 + CONTAINER="container"
60 + CONT_DETECTION="/bin/running-in-container"
61 + fi
62 +
63 + # lxc sets environment variable 'container'
64 + #shellcheck disable=SC2154
65 + if [ -n "${container}" ]; then
66 + CONTAINER="lxc"
67 + CONT_DETECTION="containerenv"
68 + fi
69 +
70 + # docker creates /.dockerenv
71 + # http://stackoverflow.com/a/25518345
72 + if [ -f "/.dockerenv" ]; then
73 + CONTAINER="docker"
74 + CONT_DETECTION="dockerenv"
75 + fi
76
77 fi
78
@@ -89,51 +89,51 @@ CONTAINER_ID="unknown"
89 CONTAINER_ID_LIKE="unknown"
90
91 if [ "${KERNEL_NAME}" = "Darwin" ]; then
92 - CONTAINER_ID=$(sw_vers -productName)
93 - CONTAINER_ID_LIKE="mac"
94 - CONTAINER_NAME="mac"
95 - CONTAINER_VERSION=$(sw_vers -productVersion)
96 - CONTAINER_OS_DETECTION="sw_vers"
92 + CONTAINER_ID=$(sw_vers -productName)
93 + CONTAINER_ID_LIKE="mac"
94 + CONTAINER_NAME="mac"
95 + CONTAINER_VERSION=$(sw_vers -productVersion)
96 + CONTAINER_OS_DETECTION="sw_vers"
97 elif [ "${KERNEL_NAME}" = "FreeBSD" ]; then
98 - CONTAINER_ID="FreeBSD"
99 - CONTAINER_ID_LIKE="FreeBSD"
100 - CONTAINER_NAME="FreeBSD"
101 - CONTAINER_OS_DETECTION="uname"
102 - CONTAINER_VERSION=$(uname -r)
103 - KERNEL_VERSION=$(uname -K)
98 + CONTAINER_ID="FreeBSD"
99 + CONTAINER_ID_LIKE="FreeBSD"
100 + CONTAINER_NAME="FreeBSD"
101 + CONTAINER_OS_DETECTION="uname"
102 + CONTAINER_VERSION=$(uname -r)
103 + KERNEL_VERSION=$(uname -K)
104 else
105 - if [ -f "/etc/os-release" ]; then
106 - eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" </etc/os-release | sed 's/^/CONTAINER_/')"
107 - CONTAINER_OS_DETECTION="/etc/os-release"
108 - fi
109 -
110 - # shellcheck disable=SC2153
111 - if [ "${NAME}" = "unknown" ] || [ "${VERSION}" = "unknown" ] || [ "${ID}" = "unknown" ]; then
112 - if [ -f "/etc/lsb-release" ]; then
113 - if [ "${OS_DETECTION}" = "unknown" ]; then
114 - CONTAINER_OS_DETECTION="/etc/lsb-release"
115 - else
116 - CONTAINER_OS_DETECTION="Mixed"
117 - fi
118 - DISTRIB_ID="unknown"
119 - DISTRIB_RELEASE="unknown"
120 - DISTRIB_CODENAME="unknown"
121 - eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" </etc/lsb-release)"
122 - if [ "${NAME}" = "unknown" ]; then CONTAINER_NAME="${DISTRIB_ID}"; fi
123 - if [ "${VERSION}" = "unknown" ]; then CONTAINER_VERSION="${DISTRIB_RELEASE}"; fi
124 - if [ "${ID}" = "unknown" ]; then CONTAINER_ID="${DISTRIB_CODENAME}"; fi
125 - fi
126 - if [ -n "$(command -v lsb_release 2>/dev/null)" ]; then
127 - if [ "${OS_DETECTION}" = "unknown" ]; then
128 - CONTAINER_OS_DETECTION="lsb_release"
129 - else
130 - CONTAINER_OS_DETECTION="Mixed"
131 - fi
132 - if [ "${NAME}" = "unknown" ]; then CONTAINER_NAME="$(lsb_release -is 2>/dev/null)"; fi
133 - if [ "${VERSION}" = "unknown" ]; then CONTAINER_VERSION="$(lsb_release -rs 2>/dev/null)"; fi
134 - if [ "${ID}" = "unknown" ]; then CONTAINER_ID="$(lsb_release -cs 2>/dev/null)"; fi
135 - fi
136 - fi
105 + if [ -f "/etc/os-release" ]; then
106 + eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /etc/os-release | sed 's/^/CONTAINER_/')"
107 + CONTAINER_OS_DETECTION="/etc/os-release"
108 + fi
109 +
110 + # shellcheck disable=SC2153
111 + if [ "${NAME}" = "unknown" ] || [ "${VERSION}" = "unknown" ] || [ "${ID}" = "unknown" ]; then
112 + if [ -f "/etc/lsb-release" ]; then
113 + if [ "${OS_DETECTION}" = "unknown" ]; then
114 + CONTAINER_OS_DETECTION="/etc/lsb-release"
115 + else
116 + CONTAINER_OS_DETECTION="Mixed"
117 + fi
118 + DISTRIB_ID="unknown"
119 + DISTRIB_RELEASE="unknown"
120 + DISTRIB_CODENAME="unknown"
121 + eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" < /etc/lsb-release)"
122 + if [ "${NAME}" = "unknown" ]; then CONTAINER_NAME="${DISTRIB_ID}"; fi
123 + if [ "${VERSION}" = "unknown" ]; then CONTAINER_VERSION="${DISTRIB_RELEASE}"; fi
124 + if [ "${ID}" = "unknown" ]; then CONTAINER_ID="${DISTRIB_CODENAME}"; fi
125 + fi
126 + if [ -n "$(command -v lsb_release 2> /dev/null)" ]; then
127 + if [ "${OS_DETECTION}" = "unknown" ]; then
128 + CONTAINER_OS_DETECTION="lsb_release"
129 + else
130 + CONTAINER_OS_DETECTION="Mixed"
131 + fi
132 + if [ "${NAME}" = "unknown" ]; then CONTAINER_NAME="$(lsb_release -is 2> /dev/null)"; fi
133 + if [ "${VERSION}" = "unknown" ]; then CONTAINER_VERSION="$(lsb_release -rs 2> /dev/null)"; fi
134 + if [ "${ID}" = "unknown" ]; then CONTAINER_ID="$(lsb_release -cs 2> /dev/null)"; fi
135 + fi
136 + fi
137 fi
138
139 # If Netdata is not running in a container then use the local detection as the host
@@ -144,32 +144,32 @@ HOST_VERSION_ID="unknown"
144 HOST_ID="unknown"
145 HOST_ID_LIKE="unknown"
146 if [ "${CONTAINER}" = "unknown" ]; then
147 - for v in NAME ID ID_LIKE VERSION VERSION_ID OS_DETECTION; do
148 - eval "HOST_$v=\$CONTAINER_$v; CONTAINER_$v=none"
149 - done
147 + for v in NAME ID ID_LIKE VERSION VERSION_ID OS_DETECTION; do
148 + eval "HOST_$v=\$CONTAINER_$v; CONTAINER_$v=none"
149 + done
150 else
151 -# Otherwise try and use a user-supplied bind-mount into the container to resolve the host details
152 - if [ -e "/host/etc/os-release" ]; then
153 - OS_DETECTION="/etc/os-release"
154 - eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" </host/etc/os-release | sed 's/^/HOST_/')"
155 - HOST_OS_DETECTION="/host/etc/os-release"
156 - fi
157 - if [ "${HOST_NAME}" = "unknown" ] || [ "${HOST_VERSION}" = "unknown" ] || [ "${HOST_ID}" = "unknown" ]; then
158 - if [ -f "/host/etc/lsb-release" ]; then
159 - if [ "${HOST_OS_DETECTION}" = "unknown" ]; then
160 - HOST_OS_DETECTION="/etc/lsb-release"
161 - else
162 - HOST_OS_DETECTION="Mixed"
163 - fi
164 - DISTRIB_ID="unknown"
165 - DISTRIB_RELEASE="unknown"
166 - DISTRIB_CODENAME="unknown"
167 - eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" </etc/lsb-release)"
168 - if [ "${HOST_NAME}" = "unknown" ]; then HOST_NAME="${DISTRIB_ID}"; fi
169 - if [ "${HOST_VERSION}" = "unknown" ]; then HOST_VERSION="${DISTRIB_RELEASE}"; fi
170 - if [ "${HOST_ID}" = "unknown" ]; then HOST_ID="${DISTRIB_CODENAME}"; fi
171 - fi
172 - fi
151 + # Otherwise try and use a user-supplied bind-mount into the container to resolve the host details
152 + if [ -e "/host/etc/os-release" ]; then
153 + OS_DETECTION="/etc/os-release"
154 + eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /host/etc/os-release | sed 's/^/HOST_/')"
155 + HOST_OS_DETECTION="/host/etc/os-release"
156 + fi
157 + if [ "${HOST_NAME}" = "unknown" ] || [ "${HOST_VERSION}" = "unknown" ] || [ "${HOST_ID}" = "unknown" ]; then
158 + if [ -f "/host/etc/lsb-release" ]; then
159 + if [ "${HOST_OS_DETECTION}" = "unknown" ]; then
160 + HOST_OS_DETECTION="/etc/lsb-release"
161 + else
162 + HOST_OS_DETECTION="Mixed"
163 + fi
164 + DISTRIB_ID="unknown"
165 + DISTRIB_RELEASE="unknown"
166 + DISTRIB_CODENAME="unknown"
167 + eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" < /etc/lsb-release)"
168 + if [ "${HOST_NAME}" = "unknown" ]; then HOST_NAME="${DISTRIB_ID}"; fi
169 + if [ "${HOST_VERSION}" = "unknown" ]; then HOST_VERSION="${DISTRIB_RELEASE}"; fi
170 + if [ "${HOST_ID}" = "unknown" ]; then HOST_ID="${DISTRIB_CODENAME}"; fi
171 + fi
172 + fi
173 fi
174
175 # -------------------------------------------------------------------------------------------------
@@ -188,93 +188,93 @@ lscpu_output=""
188 dmidecode="$(command -v dmidecode)"
189 dmidecode_output=""
190
191 -if [ -n "${lscpu}" ] && lscpu >/dev/null 2>&1 ; then
192 - lscpu_output="$(LC_NUMERIC=C ${lscpu} 2>/dev/null)"
193 - CPU_INFO_SOURCE="lscpu"
194 - LCPU_COUNT="$(echo "${lscpu_output}" | grep "^CPU(s):" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
195 - CPU_VENDOR="$(echo "${lscpu_output}" | grep "^Vendor ID:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
196 - CPU_MODEL="$(echo "${lscpu_output}" | grep "^Model name:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
197 - possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU max MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*') MHz"
198 - if [ "${possible_cpu_freq}" = " MHz" ] ; then
199 - possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*') MHz"
200 - fi
201 -elif [ -n "${dmidecode}" ] && dmidecode -t processor >/dev/null 2>&1 ; then
202 - dmidecode_output="$(${dmidecode} -t processor 2>/dev/null)"
203 - CPU_INFO_SOURCE="dmidecode"
204 - LCPU_COUNT="$(echo "${dmidecode_output}" | grep -F "Thread Count:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
205 - CPU_VENDOR="$(echo "${dmidecode_output}" | grep -F "Manufacturer:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
206 - CPU_MODEL="$(echo "${dmidecode_output}" | grep -F "Version:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
207 - possible_cpu_freq="$(echo "${dmidecode_output}" | grep -F "Current Speed:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
191 +if [ -n "${lscpu}" ] && lscpu > /dev/null 2>&1; then
192 + lscpu_output="$(LC_NUMERIC=C ${lscpu} 2> /dev/null)"
193 + CPU_INFO_SOURCE="lscpu"
194 + LCPU_COUNT="$(echo "${lscpu_output}" | grep "^CPU(s):" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
195 + CPU_VENDOR="$(echo "${lscpu_output}" | grep "^Vendor ID:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
196 + CPU_MODEL="$(echo "${lscpu_output}" | grep "^Model name:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
197 + possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU max MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*') MHz"
198 + if [ "${possible_cpu_freq}" = " MHz" ]; then
199 + possible_cpu_freq="$(echo "${lscpu_output}" | grep -F "CPU MHz:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | grep -o '^[0-9]*') MHz"
200 + fi
201 +elif [ -n "${dmidecode}" ] && dmidecode -t processor > /dev/null 2>&1; then
202 + dmidecode_output="$(${dmidecode} -t processor 2> /dev/null)"
203 + CPU_INFO_SOURCE="dmidecode"
204 + LCPU_COUNT="$(echo "${dmidecode_output}" | grep -F "Thread Count:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
205 + CPU_VENDOR="$(echo "${dmidecode_output}" | grep -F "Manufacturer:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
206 + CPU_MODEL="$(echo "${dmidecode_output}" | grep -F "Version:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
207 + possible_cpu_freq="$(echo "${dmidecode_output}" | grep -F "Current Speed:" | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
208 else
209 - if [ -n "${nproc}" ] ; then
210 - CPU_INFO_SOURCE="nproc"
211 - LCPU_COUNT="$(${nproc})"
212 - elif [ "${KERNEL_NAME}" = FreeBSD ] ; then
213 - CPU_INFO_SOURCE="sysctl"
214 - LCPU_COUNT="$(sysctl -n kern.smp.cpus)"
215 - elif [ -d /sys/devices/system/cpu ] ; then
216 - CPU_INFO_SOURCE="sysfs"
217 - # This is potentially more accurate than checking `/proc/cpuinfo`.
218 - LCPU_COUNT="$(find /sys/devices/system/cpu -mindepth 1 -maxdepth 1 -type d -name 'cpu*' | grep -cEv 'idle|freq')"
219 - elif [ -r /proc/cpuinfo ] ; then
220 - CPU_INFO_SOURCE="procfs"
221 - LCPU_COUNT="$(grep -c ^processor /proc/cpuinfo)"
222 - fi
223 -
224 - # If we have GNU uname, we can use that to get CPU info (probably).
225 - if unmae --version 2>/dev/null | grep -qF 'GNU coreutils' ; then
226 - CPU_INFO_SOURCE="${CPU_INFO_SOURCE} uname"
227 - CPU_MODEL="$(uname -p)"
228 - CPU_VENDOR="$(uname -i)"
229 - elif [ "${KERNEL_NAME}" = FreeBSD ] ; then
230 - if ( echo "${CPU_INFO_SOURCE}" | grep -qv sysctl ) ; then
231 - CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysctl"
232 - fi
233 -
234 - CPU_MODEL="$(sysctl -n hw.model)"
235 - elif [ -r /proc/cpuinfo ] ; then
236 - if ( echo "${CPU_INFO_SOURCE}" | grep -qv procfs ) ; then
237 - CPU_INFO_SOURCE="${CPU_INFO_SOURCE} procfs"
238 - fi
239 -
240 - CPU_MODEL="$(grep -F "model name" /proc/cpuinfo | head -n 1 | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
241 - CPU_VENDOR="$(grep -F "vendor_id" /proc/cpuinfo | head -n 1 | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
242 - fi
243 -fi
244 -
245 -if [ -r /sys/devices/system/cpu/cpu0/cpufreq/base_frequency ] ; then
246 - if ( echo "${CPU_INFO_SOURCE}" | grep -qv sysfs ) ; then
247 - CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysfs"
209 + if [ -n "${nproc}" ]; then
210 + CPU_INFO_SOURCE="nproc"
211 + LCPU_COUNT="$(${nproc})"
212 + elif [ "${KERNEL_NAME}" = FreeBSD ]; then
213 + CPU_INFO_SOURCE="sysctl"
214 + LCPU_COUNT="$(sysctl -n kern.smp.cpus)"
215 + elif [ -d /sys/devices/system/cpu ]; then
216 + CPU_INFO_SOURCE="sysfs"
217 + # This is potentially more accurate than checking `/proc/cpuinfo`.
218 + LCPU_COUNT="$(find /sys/devices/system/cpu -mindepth 1 -maxdepth 1 -type d -name 'cpu*' | grep -cEv 'idle|freq')"
219 + elif [ -r /proc/cpuinfo ]; then
220 + CPU_INFO_SOURCE="procfs"
221 + LCPU_COUNT="$(grep -c ^processor /proc/cpuinfo)"
222 + fi
223 +
224 + # If we have GNU uname, we can use that to get CPU info (probably).
225 + if uname --version 2> /dev/null | grep -qF 'GNU coreutils'; then
226 + CPU_INFO_SOURCE="${CPU_INFO_SOURCE} uname"
227 + CPU_MODEL="$(uname -p)"
228 + CPU_VENDOR="$(uname -i)"
229 + elif [ "${KERNEL_NAME}" = FreeBSD ]; then
230 + if (echo "${CPU_INFO_SOURCE}" | grep -qv sysctl); then
231 + CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysctl"
232 fi
233
250 - CPU_FREQ="$(cat /sys/devices/system/cpu/cpu0/cpufreq/base_frequency)"
251 -elif [ -n "${possible_cpu_freq}" ] ; then
252 - CPU_FREQ="${possible_cpu_freq}"
253 -elif [ -r /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq ] ; then
254 - if ( echo "${CPU_INFO_SOURCE}" | grep -qv sysfs ) ; then
255 - CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysfs"
234 + CPU_MODEL="$(sysctl -n hw.model)"
235 + elif [ -r /proc/cpuinfo ]; then
236 + if (echo "${CPU_INFO_SOURCE}" | grep -qv procfs); then
237 + CPU_INFO_SOURCE="${CPU_INFO_SOURCE} procfs"
238 fi
239
258 - CPU_FREQ="$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)"
240 + CPU_MODEL="$(grep -F "model name" /proc/cpuinfo | head -n 1 | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
241 + CPU_VENDOR="$(grep -F "vendor_id" /proc/cpuinfo | head -n 1 | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
242 + fi
243 +fi
244 +
245 +if [ -r /sys/devices/system/cpu/cpu0/cpufreq/base_frequency ]; then
246 + if (echo "${CPU_INFO_SOURCE}" | grep -qv sysfs); then
247 + CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysfs"
248 + fi
249 +
250 + CPU_FREQ="$(cat /sys/devices/system/cpu/cpu0/cpufreq/base_frequency)"
251 +elif [ -n "${possible_cpu_freq}" ]; then
252 + CPU_FREQ="${possible_cpu_freq}"
253 +elif [ -r /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq ]; then
254 + if (echo "${CPU_INFO_SOURCE}" | grep -qv sysfs); then
255 + CPU_INFO_SOURCE="${CPU_INFO_SOURCE} sysfs"
256 + fi
257 +
258 + CPU_FREQ="$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)"
259 fi
260
261 freq_units="$(echo "${CPU_FREQ}" | cut -f 2 -d ' ')"
262
263 case "${freq_units}" in
264 - GHz)
265 - value="$(echo "${CPU_FREQ}" | cut -f 1 -d ' ')"
266 - CPU_FREQ="$((value*1000*1000*1000))"
267 - ;;
268 - MHz)
269 - value="$(echo "${CPU_FREQ}" | cut -f 1 -d ' ')"
270 - CPU_FREQ="$((value*1000*1000))"
271 - ;;
272 - KHz)
273 - value="$(echo "${CPU_FREQ}" | cut -f 1 -d ' ')"
274 - CPU_FREQ="$((value*1000))"
275 - ;;
276 - *)
277 - ;;
264 + GHz)
265 + value="$(echo "${CPU_FREQ}" | cut -f 1 -d ' ')"
266 + CPU_FREQ="$((value * 1000 * 1000 * 1000))"
267 + ;;
268 + MHz)
269 + value="$(echo "${CPU_FREQ}" | cut -f 1 -d ' ')"
270 + CPU_FREQ="$((value * 1000 * 1000))"
271 + ;;
272 + KHz)
273 + value="$(echo "${CPU_FREQ}" | cut -f 1 -d ' ')"
274 + CPU_FREQ="$((value * 1000))"
275 + ;;
276 + *) ;;
277 +
278 esac
279
280 # -------------------------------------------------------------------------------------------------
@@ -283,16 +283,16 @@ esac
283 TOTAL_RAM="unknown"
284 RAM_DETECTION="none"
285
286 -if [ "${KERNEL_NAME}" = FreeBSD ] ; then
287 - RAM_DETECTION="sysctl"
288 - TOTAL_RAM="$(sysctl -n hw.physmem)"
289 -elif [ "${KERNEL_NAME}" = Darwin ] ; then
290 - RAM_DETECTION="sysctl"
291 - TOTAL_RAM="$(sysctl -n hw.physmem)"
292 -elif [ -r /proc/meminfo ] ; then
293 - RAM_DETECTION="procfs"
294 - TOTAL_RAM="$(grep -F MemTotal /proc/meminfo | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -f 1 -d ' ')"
295 - TOTAL_RAM="$((TOTAL_RAM*1024))"
286 +if [ "${KERNEL_NAME}" = FreeBSD ]; then
287 + RAM_DETECTION="sysctl"
288 + TOTAL_RAM="$(sysctl -n hw.physmem)"
289 +elif [ "${KERNEL_NAME}" = Darwin ]; then
290 + RAM_DETECTION="sysctl"
291 + TOTAL_RAM="$(sysctl -n hw.physmem)"
292 +elif [ -r /proc/meminfo ]; then
293 + RAM_DETECTION="procfs"
294 + TOTAL_RAM="$(grep -F MemTotal /proc/meminfo | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -f 1 -d ' ')"
295 + TOTAL_RAM="$((TOTAL_RAM * 1024))"
296 fi
297
298 # -------------------------------------------------------------------------------------------------
@@ -302,65 +302,76 @@ DISK_SIZE="unknown"
302 DISK_DETECTION="none"
303
304 if [ "${KERNEL_NAME}" = "Darwin" ]; then
305 - types='hfs'
305 + types='hfs'
306
307 - if (lsvfs | grep -q apfs) ; then
308 - types="${types},apfs"
309 - fi
307 + if (lsvfs | grep -q apfs); then
308 + types="${types},apfs"
309 + fi
310
311 - if (lsvfs | grep -q ufs) ; then
312 - types="${types},ufs"
313 - fi
311 + if (lsvfs | grep -q ufs); then
312 + types="${types},ufs"
313 + fi
314
315 - DISK_DETECTION="df"
316 - DISK_SIZE=$(($(/bin/df -k -t ${types} | tail -n +2 | sed -E 's/\/dev\/disk([[:digit:]]*)s[[:digit:]]*/\/dev\/disk\1/g' | sort -k 1 | awk -F ' ' '{s=$NF;for(i=NF-1;i>=1;i--)s=s FS $i;print s}' | uniq -f 9 | awk '{print $8}' | tr '\n' '+' | rev | cut -f 2- -d '+' | rev) * 1024))
317 -elif [ "${KERNEL_NAME}" = FreeBSD ] ; then
318 - types='ufs'
315 + DISK_DETECTION="df"
316 + DISK_SIZE=$(($(/bin/df -k -t ${types} | tail -n +2 | sed -E 's/\/dev\/disk([[:digit:]]*)s[[:digit:]]*/\/dev\/disk\1/g' | sort -k 1 | awk -F ' ' '{s=$NF;for(i=NF-1;i>=1;i--)s=s FS $i;print s}' | uniq -f 9 | awk '{print $8}' | tr '\n' '+' | rev | cut -f 2- -d '+' | rev) * 1024))
317 +elif [ "${KERNEL_NAME}" = FreeBSD ]; then
318 + types='ufs'
319
320 - if (lsvfs | grep -q zfs) ; then
321 - types="${types},zfs"
322 - fi
320 + if (lsvfs | grep -q zfs); then
321 + types="${types},zfs"
322 + fi
323
324 - DISK_DETECTION="df"
325 - total="$(df -t ${types} -c -k | tail -n 1 | awk '{print $2}')"
326 - DISK_SIZE="$((total * 1024))"
324 + DISK_DETECTION="df"
325 + total="$(df -t ${types} -c -k | tail -n 1 | awk '{print $2}')"
326 + DISK_SIZE="$((total * 1024))"
327 else
328 - if [ -d /sys/block ] && [ -r /proc/devices ] ; then
329 - dev_major_whitelist=''
330 -
331 - # This is a list of device names used for block storage devices.
332 - # These translate to the prefixs of files in `/dev` indicating the device type.
333 - # They are sorted by lowest used device major number, with dynamically assigned ones at the end.
334 - # We use this to look up device major numbers in `/proc/devices`
335 - device_names='hd sd mfm ad ftl pd nftl dasd intfl mmcblk ub xvd rfd vbd nvme'
336 -
337 - for name in ${device_names} ; do
338 - if grep -qE " ${name}\$" /proc/devices ; then
339 - dev_major_whitelist="${dev_major_whitelist}:$(grep -E "${name}\$" /proc/devices | sed -e 's/^[[:space:]]*//' | cut -f 1 -d ' ' | tr '\n' ':'):"
340 - fi
341 - done
342 -
343 - DISK_DETECTION="sysfs"
344 - DISK_SIZE="0"
345 - for disk in /sys/block/* ; do
346 - if [ -r "${disk}/size" ] && \
347 - (echo "${dev_major_whitelist}" | grep -q ":$(cut -f 1 -d ':' "${disk}/dev"):") && \
348 - grep -qv 1 "${disk}/removable"
349 - then
350 - size="$(($(cat "${disk}/size") * 512))"
351 - DISK_SIZE="$((DISK_SIZE + size))"
352 - fi
353 - done
354 - elif df --version 2>/dev/null | grep -qF "GNU coreutils" ; then
355 - DISK_DETECTION="df"
356 - DISK_SIZE=$(($(df -x tmpfs -x devtmpfs -x squashfs -l -B1 --output=source,size | tail -n +2 | sort -u -k 1 | awk '{print $2}' | tr '\n' '+' | head -c -1)))
357 - else
358 - DISK_DETECTION="df"
359 - include_fs_types="ext*|btrfs|xfs|jfs|reiser*|zfs"
360 - DISK_SIZE=$(($(df -T -P | tail -n +2 | sort -u -k 1 | grep "${include_fs_types}" | awk '{print $3}' | tr '\n' '+' | head -c -1) * 1024))
361 - fi
328 + if [ -d /sys/block ] && [ -r /proc/devices ]; then
329 + dev_major_whitelist=''
330 +
331 + # This is a list of device names used for block storage devices.
332 + # These translate to the prefixs of files in `/dev` indicating the device type.
333 + # They are sorted by lowest used device major number, with dynamically assigned ones at the end.
334 + # We use this to look up device major numbers in `/proc/devices`
335 + device_names='hd sd mfm ad ftl pd nftl dasd intfl mmcblk ub xvd rfd vbd nvme'
336 +
337 + for name in ${device_names}; do
338 + if grep -qE " ${name}\$" /proc/devices; then
339 + dev_major_whitelist="${dev_major_whitelist}:$(grep -E "${name}\$" /proc/devices | sed -e 's/^[[:space:]]*//' | cut -f 1 -d ' ' | tr '\n' ':'):"
340 + fi
341 + done
342 +
343 + DISK_DETECTION="sysfs"
344 + DISK_SIZE="0"
345 + for disk in /sys/block/*; do
346 + if [ -r "${disk}/size" ] \
347 + && (echo "${dev_major_whitelist}" | grep -q ":$(cut -f 1 -d ':' "${disk}/dev"):") \
348 + && grep -qv 1 "${disk}/removable"; then
349 + size="$(($(cat "${disk}/size") * 512))"
350 + DISK_SIZE="$((DISK_SIZE + size))"
351 + fi
352 + done
353 + elif df --version 2> /dev/null | grep -qF "GNU coreutils"; then
354 + DISK_DETECTION="df"
355 + DISK_SIZE=$(($(df -x tmpfs -x devtmpfs -x squashfs -l -B1 --output=source,size | tail -n +2 | sort -u -k 1 | awk '{print $2}' | tr '\n' '+' | head -c -1)))
356 + else
357 + DISK_DETECTION="df"
358 + include_fs_types="ext*|btrfs|xfs|jfs|reiser*|zfs"
359 + DISK_SIZE=$(($(df -T -P | tail -n +2 | sort -u -k 1 | grep "${include_fs_types}" | awk '{print $3}' | tr '\n' '+' | head -c -1) * 1024))
360 + fi
361 fi
362
363 +# -------------------------------------------------------------------------------------------------
364 +# Detect whether the node is kubernetes node
365 +
366 +HOST_IS_K8S_NODE="false"
367 +
368 +if [ -n "${KUBERNETES_SERVICE_HOST}" ] && [ -n "${KUBERNETES_SERVICE_PORT}" ]; then
369 + # These env vars are set for every container managed by k8s.
370 + HOST_IS_K8S_NODE="true"
371 +elif pgrep "kubelet"; then
372 + # The kubelet is the primary "node agent" that runs on each node.
373 + HOST_IS_K8S_NODE="true"
374 +fi
375
376 echo "NETDATA_CONTAINER_OS_NAME=${CONTAINER_NAME}"
377 echo "NETDATA_CONTAINER_OS_ID=${CONTAINER_ID}"
@@ -374,6 +385,7 @@ echo "NETDATA_HOST_OS_ID_LIKE=${HOST_ID_LIKE}"
385 echo "NETDATA_HOST_OS_VERSION=${HOST_VERSION}"
386 echo "NETDATA_HOST_OS_VERSION_ID=${HOST_VERSION_ID}"
387 echo "NETDATA_HOST_OS_DETECTION=${HOST_OS_DETECTION}"
388 +echo "NETDATA_HOST_IS_K8S_NODE=${HOST_IS_K8S_NODE}"
389 echo "NETDATA_SYSTEM_KERNEL_NAME=${KERNEL_NAME}"
390 echo "NETDATA_SYSTEM_KERNEL_VERSION=${KERNEL_VERSION}"
391 echo "NETDATA_SYSTEM_ARCHITECTURE=${ARCHITECTURE}"
@@ -390,4 +402,3 @@ echo "NETDATA_SYSTEM_TOTAL_RAM=${TOTAL_RAM}"
402 echo "NETDATA_SYSTEM_RAM_DETECTION=${RAM_DETECTION}"
403 echo "NETDATA_SYSTEM_TOTAL_DISK_SIZE=${DISK_SIZE}"
404 echo "NETDATA_SYSTEM_DISK_DETECTION=${DISK_DETECTION}"
393 -
database/rrd.h
+1
@@ -721,6 +721,7 @@ struct rrdhost_system_info {
721 char *virt_detection;
722 char *container;
723 char *container_detection;
724 + char *is_k8s_node;
725 };
726
727 struct rrdhost {
database/rrdhost.c
+9
@@ -758,6 +758,7 @@ void rrdhost_system_info_free(struct rrdhost_system_info *system_info) {
758 freez(system_info->virt_detection);
759 freez(system_info->container);
760 freez(system_info->container_detection);
761 + freez(system_info->is_k8s_node);
762 freez(system_info);
763 }
764 }
@@ -982,6 +983,10 @@ static struct label *rrdhost_load_auto_labels(void)
983 label_list =
984 add_label_to_list(label_list, "_virt_detection", localhost->system_info->virt_detection, LABEL_SOURCE_AUTO);
985
986 + if (localhost->system_info->is_k8s_node)
987 + label_list =
988 + add_label_to_list(label_list, "_is_k8s_node", localhost->system_info->is_k8s_node, LABEL_SOURCE_AUTO);
989 +
990 label_list = add_label_to_list(
991 label_list, "_is_parent", (localhost->next || configured_as_parent()) ? "true" : "false", LABEL_SOURCE_AUTO);
992
@@ -1523,6 +1528,10 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch
1528 freez(system_info->container_detection);
1529 system_info->container_detection = strdupz(value);
1530 }
1531 + else if(!strcmp(name, "NETDATA_HOST_IS_K8S_NODE")){
1532 + freez(system_info->is_k8s_node);
1533 + system_info->is_k8s_node = strdupz(value);
1534 + }
1535 else if (!strcmp(name, "NETDATA_SYSTEM_CPU_VENDOR"))
1536 return res;
1537 else if (!strcmp(name, "NETDATA_SYSTEM_CPU_MODEL"))
docs/guides/using-host-labels.md
+2
@@ -50,6 +50,7 @@ read the status of your agent. For example, from a VPS system running Debian 10:
50 {
51 ...
52 "host_labels": {
53 + "_is_k8s_node": "false",
54 "_is_parent": "false",
55 "_virt_detection": "systemd-detect-virt",
56 "_container_detection": "none",
@@ -81,6 +82,7 @@ They capture the following:
82 - Operating system name and version
83 - CPU architecture, system cores, CPU frequency, RAM, and disk space
84 - Whether Netdata is running inside of a container, and if so, the OS and hardware details about the container's host
85 +- Whether Netdata is running inside K8s node
86 - What virtualization layer the system runs on top of, if any
87 - Whether the system is a streaming parent or child
88
streaming/sender.c
+2
@@ -221,6 +221,7 @@ static int rrdpush_sender_thread_connect_to_parent(RRDHOST *host, int default_po
221 "&NETDATA_SYSTEM_OS_VERSION=%s"
222 "&NETDATA_SYSTEM_OS_VERSION_ID=%s"
223 "&NETDATA_SYSTEM_OS_DETECTION=%s"
224 + "&NETDATA_HOST_IS_K8S_NODE=%s"
225 "&NETDATA_SYSTEM_KERNEL_NAME=%s"
226 "&NETDATA_SYSTEM_KERNEL_VERSION=%s"
227 "&NETDATA_SYSTEM_ARCHITECTURE=%s"
@@ -257,6 +258,7 @@ static int rrdpush_sender_thread_connect_to_parent(RRDHOST *host, int default_po
258 , se.os_version
259 , (host->system_info->host_os_version_id) ? host->system_info->host_os_version_id : ""
260 , (host->system_info->host_os_detection) ? host->system_info->host_os_detection : ""
261 + , (host->system_info->is_k8s_node) ? host->system_info->is_k8s_node : ""
262 , se.kernel_name
263 , se.kernel_version
264 , (host->system_info->architecture) ? host->system_info->architecture : ""
web/api/netdata-swagger.json
+6 -1
@@ -9,7 +9,7 @@
9 "/info": {
10 "get": {
11 "summary": "Get netdata basic information",
12 - "description": "The info endpoint returns basic information about netdata. It provides:\n* netdata version\n* netdata unique id\n* list of hosts mirrored (includes itself)\n* Operating System, Virtualization and Container technology information\n* List of active collector plugins and modules\n* number of alarms in the host\n * number of alarms in normal state\n * number of alarms in warning state\n * number of alarms in critical state\n",
12 + "description": "The info endpoint returns basic information about netdata. It provides:\n* netdata version\n* netdata unique id\n* list of hosts mirrored (includes itself)\n* Operating System, Virtualization, K8s nodes and Container technology information\n* List of active collector plugins and modules\n* number of alarms in the host\n * number of alarms in normal state\n * number of alarms in warning state\n * number of alarms in critical state\n",
13 "responses": {
14 "200": {
15 "description": "netdata basic information.",
@@ -1172,6 +1172,11 @@
1172 "description": "Kernel Version.",
1173 "example": "4.19.32-1-MANJARO"
1174 },
1175 + "is_k8s_node": {
1176 + "type": "boolean",
1177 + "description": "Netdata is running on a K8s node.",
1178 + "example": false
1179 + },
1180 "architecture": {
1181 "type": "string",
1182 "description": "Kernel architecture.",
web/api/netdata-swagger.yaml
+5 -1
@@ -12,7 +12,7 @@ paths:
12 * netdata version
13 * netdata unique id
14 * list of hosts mirrored (includes itself)
15 - * Operating System, Virtualization and Container technology information
15 + * Operating System, Virtualization, K8s nodes and Container technology information
16 * List of active collector plugins and modules
17 * number of alarms in the host
18 * number of alarms in normal state
@@ -948,6 +948,10 @@ components:
948 type: string
949 description: Kernel Version.
950 example: 4.19.32-1-MANJARO
951 + is_k8s_node:
952 + type: boolean
953 + description: Netdata is running on a K8s node.
954 + example: false
955 architecture:
956 type: string
957 description: Kernel architecture.
web/api/web_api_v1.c
+2
@@ -933,6 +933,8 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
933 buffer_sprintf(wb, "\t\"container_os_version_id\": \"%s\",\n", host->system_info->container_os_version_id);
934 if (host->system_info->container_os_detection)
935 buffer_sprintf(wb, "\t\"container_os_detection\": \"%s\",\n", host->system_info->container_os_detection);
936 + if (host->system_info->is_k8s_node)
937 + buffer_sprintf(wb, "\t\"is_k8s_node\": \"%s\",\n", host->system_info->is_k8s_node);
938
939 buffer_sprintf(wb, "\t\"kernel_name\": \"%s\",\n", (host->system_info->kernel_name) ? host->system_info->kernel_name : "");
940 buffer_sprintf(wb, "\t\"kernel_version\": \"%s\",\n", (host->system_info->kernel_version) ? host->system_info->kernel_version : "");