summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Moss <1043609+amoss@users.noreply.github.com>2020-01-21 16:08:59 +0100
committerGitHub <noreply@github.com>2020-01-21 16:08:59 +0100
commit49f6950820f083956ddc2c9327eeae4e9ef0d5ed (patch)
treec551bb219e2503c55e3b4e668408d4bff9ac99d8
parent434c9ba6e17aa80548e1fccbcadccaa1572d76eb (diff)
Issue 7488 docker labels (#7770)
Improve the metadata detection for containers. The system_info structure has been updated to hold separate copies of OS_NAME, OS_ID, OS_ID_LIKE, OS_VERSION, OS_VERSION_ID and OS_DETECTION for both the container environment and the host. This new information is communicated through the /api/v1/info endpoint. For the streaming interface a partial copy of the info is carried until the stream protocol is upgraded. The anonymous_statistics script has been updated to carry the new data to Google Analytics. Some minor improvements have been made to OS-X / FreeBSD detection, and the detection of virtualization. The docs have been updated to explain how to pass the host environment to the docker container running Netdata.
-rwxr-xr-xdaemon/anonymous-statistics.sh.in37
-rw-r--r--daemon/main.c36
-rwxr-xr-xdaemon/system-info.sh245
-rw-r--r--database/rrd.h18
-rw-r--r--database/rrdhost.c96
-rw-r--r--packaging/docker/README.md23
-rw-r--r--streaming/rrdpush.c31
-rw-r--r--web/api/web_api_v1.c26
8 files changed, 347 insertions, 165 deletions
diff --git a/daemon/anonymous-statistics.sh.in b/daemon/anonymous-statistics.sh.in
index f16c85a459..1aa0a7c67d 100755
--- a/daemon/anonymous-statistics.sh.in
+++ b/daemon/anonymous-statistics.sh.in
@@ -28,6 +28,7 @@ NETDATA_VERSION=$(echo "${NETDATA_VERSION}" | sed 's/-.*//g' | tr -d 'v')
# -------------------------------------------------------------------------------------------------
# send the anonymous statistics to GA
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
+# The maximum index for a cd parameter is 20 so we have effectively run out.
if [ -n "$(command -v curl 2>/dev/null)" ]; then
curl -X POST -Ss --max-time 2 \
--data "v=1" \
@@ -43,12 +44,12 @@ if [ -n "$(command -v curl 2>/dev/null)" ]; then
--data-urlencode "ec=${ACTION}" \
--data-urlencode "ea=${ACTION_RESULT}" \
--data-urlencode "el=${ACTION_DATA}" \
- --data-urlencode "cd1=${NETDATA_SYSTEM_OS_NAME}" \
- --data-urlencode "cd2=${NETDATA_SYSTEM_OS_ID}" \
- --data-urlencode "cd3=${NETDATA_SYSTEM_OS_ID_LIKE}" \
- --data-urlencode "cd4=${NETDATA_SYSTEM_OS_VERSION}" \
- --data-urlencode "cd5=${NETDATA_SYSTEM_OS_VERSION_ID}" \
- --data-urlencode "cd6=${NETDATA_SYSTEM_OS_DETECTION}" \
+ --data-urlencode "cd1=${NETDATA_HOST_OS_NAME}" \
+ --data-urlencode "cd2=${NETDATA_HOST_OS_ID}" \
+ --data-urlencode "cd3=${NETDATA_HOST_OS_ID_LIKE}" \
+ --data-urlencode "cd4=${NETDATA_HOST_OS_VERSION}" \
+ --data-urlencode "cd5=${NETDATA_HOST_OS_VERSION_ID}" \
+ --data-urlencode "cd6=${NETDATA_HOST_OS_DETECTION}" \
--data-urlencode "cd7=${NETDATA_SYSTEM_KERNEL_NAME}" \
--data-urlencode "cd8=${NETDATA_SYSTEM_KERNEL_VERSION}" \
--data-urlencode "cd9=${NETDATA_SYSTEM_ARCHITECTURE}" \
@@ -56,6 +57,12 @@ if [ -n "$(command -v curl 2>/dev/null)" ]; then
--data-urlencode "cd11=${NETDATA_SYSTEM_VIRT_DETECTION}" \
--data-urlencode "cd12=${NETDATA_SYSTEM_CONTAINER}" \
--data-urlencode "cd13=${NETDATA_SYSTEM_CONTAINER_DETECTION}" \
+ --data-urlencode "cd14=${NETDATA_CONTAINER_OS_NAME}" \
+ --data-urlencode "cd15=${NETDATA_CONTAINER_OS_ID}" \
+ --data-urlencode "cd16=${NETDATA_CONTAINER_OS_ID_LIKE}" \
+ --data-urlencode "cd17=${NETDATA_CONTAINER_OS_VERSION}" \
+ --data-urlencode "cd18=${NETDATA_CONTAINER_OS_VERSION_ID}" \
+ --data-urlencode "cd19=${NETDATA_CONTAINER_OS_DETECTION}" \
"https://www.google-analytics.com/collect" >/dev/null 2>&1
else
wget -q -O - --timeout=1 "https://www.google-analytics.com/collect?\
@@ -72,12 +79,12 @@ else
&ec=${ACTION}\
&ea=${ACTION_RESULT}\
&el=${ACTION_DATA}\
-&cd1=${NETDATA_SYSTEM_OS_NAME}\
-&cd2=${NETDATA_SYSTEM_OS_ID}\
-&cd3=${NETDATA_SYSTEM_OS_ID_LIKE}\
-&cd4=${NETDATA_SYSTEM_OS_VERSION}\
-&cd5=${NETDATA_SYSTEM_OS_VERSION_ID}\
-&cd6=${NETDATA_SYSTEM_OS_DETECTION}\
+&cd1=${NETDATA_HOST_OS_NAME}\
+&cd2=${NETDATA_HOST_OS_ID}\
+&cd3=${NETDATA_HOST_OS_ID_LIKE}\
+&cd4=${NETDATA_HOST_OS_VERSION}\
+&cd5=${NETDATA_HOST_OS_VERSION_ID}\
+&cd6=${NETDATA_HOST_OS_DETECTION}\
&cd7=${NETDATA_SYSTEM_KERNEL_NAME}\
&cd8=${NETDATA_SYSTEM_KERNEL_VERSION}\
&cd9=${NETDATA_SYSTEM_ARCHITECTURE}\
@@ -85,5 +92,11 @@ else
&cd11=${NETDATA_SYSTEM_VIRT_DETECTION}\
&cd12=${NETDATA_SYSTEM_CONTAINER}\
&cd13=${NETDATA_SYSTEM_CONTAINER_DETECTION}\
+&cd14=${NETDATA_CONTAINER_OS_NAME} \
+&cd15=${NETDATA_CONTAINER_OS_ID} \
+&cd16=${NETDATA_CONTAINER_OS_ID_LIKE} \
+&cd17=${NETDATA_CONTAINER_OS_VERSION} \
+&cd18=${NETDATA_CONTAINER_OS_VERSION_ID} \
+&cd19=${NETDATA_CONTAINER_OS_DETECTION} \
" > /dev/null 2>&1
fi
diff --git a/daemon/main.c b/daemon/main.c
index 9eb424c535..be77fae81d 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -731,6 +731,12 @@ static int load_netdata_conf(char *filename, char overwrite_used) {
return ret;
}
+// coverity[ +tainted_string_sanitize_content : arg-0 ]
+inline void coverity_remove_taint(char *s)
+{
+ (void)s;
+}
+
int get_system_info(struct rrdhost_system_info *system_info) {
char *script;
script = mallocz(sizeof(char) * (strlen(netdata_configured_primary_plugins_dir) + strlen("system-info.sh") + 2));
@@ -747,27 +753,27 @@ int get_system_info(struct rrdhost_system_info *system_info) {
FILE *fp = mypopen(script, &command_pid);
if(fp) {
- char buffer[200 + 1];
- while (fgets(buffer, 200, fp) != NULL) {
- char *name=buffer;
- char *value=buffer;
+ char line[200 + 1];
+ // Removed the double strlens, if the Coverity tainted string warning reappears I'll revert.
+ // One time init code, but I'm curious about the warning...
+ while (fgets(line, 200, fp) != NULL) {
+ char *value=line;
while (*value && *value != '=') value++;
if (*value=='=') {
*value='\0';
value++;
- if (strlen(value)>1) {
- char *newline = value + strlen(value) - 1;
- (*newline) = '\0';
- }
- char n[51], v[101];
- snprintfz(n, 50,"%s",name);
- snprintfz(v, 100,"%s",value);
- if(unlikely(rrdhost_set_system_info_variable(system_info, n, v))) {
- info("Unexpected environment variable %s=%s", n, v);
+ char *end = value;
+ while (*end && *end != '\n') end++;
+ *end = '\0'; // Overwrite newline if present
+ coverity_remove_taint(line); // I/O is controlled result of system_info.sh - not tainted
+ coverity_remove_taint(value);
+
+ if(unlikely(rrdhost_set_system_info_variable(system_info, line, value))) {
+ info("Unexpected environment variable %s=%s", line, value);
}
else {
- info("%s=%s", n, v);
- setenv(n, v, 1);
+ info("%s=%s", line, value);
+ setenv(line, value, 1);
}
}
}
diff --git a/daemon/system-info.sh b/daemon/system-info.sh
index 7b091a9e54..cd3fc6ee97 100755
--- a/daemon/system-info.sh
+++ b/daemon/system-info.sh
@@ -8,111 +8,180 @@ KERNEL_VERSION="$(uname -r)"
ARCHITECTURE="$(uname -m)"
# -------------------------------------------------------------------------------------------------
-# detect the operating system
+# detect the virtualization
-OS_DETECTION="unknown"
-NAME="unknown"
-VERSION="unknown"
-VERSION_ID="unknown"
-ID="unknown"
-ID_LIKE="unknown"
+if [ -z "${VIRTUALIZATION}" ]; then
+ VIRTUALIZATION="unknown"
+ VIRT_DETECTION="none"
-if [ "${KERNEL_NAME}" = "Darwin" ]; then
- # Mac OS
- OIFS="$IFS"
- IFS=$'\n'
- set $(sw_vers) > /dev/null
- NAME=$(echo $1 | tr "\n\t" ' ' | sed -e 's/ProductName:[ ]*//' -e 's/[ ]*$//')
- VERSION=$(echo $2 | tr "\n\t" ' ' | sed -e 's/ProductVersion:[ ]*//' -e 's/[ ]*$//')
- ID="mac"
- ID_LIKE="mac"
- OS_DETECTION="sw_vers"
- IFS="$OIFS"
+ if [ -n "$(command -v systemd-detect-virt 2>/dev/null)" ]; then
+ VIRTUALIZATION="$(systemd-detect-virt -v)"
+ VIRT_DETECTION="systemd-detect-virt"
+ CONTAINER="$(systemd-detect-virt -c)"
+ CONT_DETECTION="systemd-detect-virt"
+ else
+ if grep -q "^flags.*hypervisor" /proc/cpuinfo 2>/dev/null; then
+ VIRTUALIZATION="hypervisor"
+ VIRT_DETECTION="/proc/cpuinfo"
+ elif [ -n "$(command -v dmidecode)" ]; then
+ # Virtualization detection from https://unix.stackexchange.com/questions/89714/easy-way-to-determine-virtualization-technology
+ # This only works as root
+ if dmidecode -s system-product-name 2>/dev/null | grep -q "VMware\|Virtual\|KVM\|Bochs"; then
+ VIRTUALIZATION="$(dmidecode -s system-product-name)"
+ VIRT_DETECTION="dmidecode"
+ fi
+ fi
+ fi
else
- if [ -f "/etc/os-release" ]; then
- OS_DETECTION="/etc/os-release"
- eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" </etc/os-release)"
- fi
-
- if [ "${NAME}" = "unknown" ] || [ "${VERSION}" = "unknown" ] || [ "${ID}" = "unknown" ]; then
- if [ -f "/etc/lsb-release" ]; then
- if [ "${OS_DETECTION}" = "unknown" ]; then OS_DETECTION="/etc/lsb-release"; else OS_DETECTION="Mixed"; fi
- DISTRIB_ID="unknown"
- DISTRIB_RELEASE="unknown"
- DISTRIB_CODENAME="unknown"
- eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" </etc/lsb-release)"
- if [ "${NAME}" = "unknown" ]; then NAME="${DISTRIB_ID}"; fi
- if [ "${VERSION}" = "unknown" ]; then VERSION="${DISTRIB_RELEASE}"; fi
- if [ "${ID}" = "unknown" ]; then ID="${DISTRIB_CODENAME}"; fi
- fi
- if [ -n "$(command -v lsb_release 2>/dev/null)" ]; then
- if [ "${OS_DETECTION}" = "unknown" ]; then OS_DETECTION="lsb_release"; else OS_DETECTION="Mixed"; fi
- if [ "${NAME}" = "unknown" ]; then NAME="$(lsb_release -is 2>/dev/null)"; fi
- if [ "${VERSION}" = "unknown" ]; then VERSION="$(lsb_release -rs 2>/dev/null)"; fi
- if [ "${ID}" = "unknown" ]; then ID="$(lsb_release -cs 2>/dev/null)"; fi
- fi
- fi
+ # Passed from outside - probably in docker run
+ VIRT_DETECTION="provided"
fi
# -------------------------------------------------------------------------------------------------
-# detect the virtualization
+# detect containers with heuristics
-VIRTUALIZATION="unknown"
-VIRT_DETECTION="none"
CONTAINER="unknown"
CONT_DETECTION="none"
-if [ -n "$(command -v systemd-detect-virt 2>/dev/null)" ]; then
- VIRTUALIZATION="$(systemd-detect-virt -v)"
- VIRT_DETECTION="systemd-detect-virt"
- CONTAINER="$(systemd-detect-virt -c)"
- CONT_DETECTION="systemd-detect-virt"
-else
- if grep -q "^flags.*hypervisor" /proc/cpuinfo 2>/dev/null; then
- VIRTUALIZATION="hypervisor"
- VIRT_DETECTION="/proc/cpuinfo"
- fi
+if [ "${CONTAINER}" = "unknown" ]; then
+ if [ -f /proc/1/sched ] ; then
+ IFS='(, ' read -r process _ </proc/1/sched
+ if [ "${process}" = "netdata" ]; then
+ CONTAINER="container"
+ CONT_DETECTION="process"
+ fi
+ fi
+ # ubuntu and debian supply /bin/running-in-container
+ # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
+ if /bin/running-in-container >/dev/null 2>&1; then
+ CONTAINER="container"
+ CONT_DETECTION="/bin/running-in-container"
+ fi
+
+ # lxc sets environment variable 'container'
+ #shellcheck disable=SC2154
+ if [ -n "${container}" ]; then
+ CONTAINER="lxc"
+ CONT_DETECTION="containerenv"
+ fi
+
+ # docker creates /.dockerenv
+ # http://stackoverflow.com/a/25518345
+ if [ -f "/.dockerenv" ]; then
+ CONTAINER="docker"
+ CONT_DETECTION="dockerenv"
+ fi
+
fi
# -------------------------------------------------------------------------------------------------
-# detect containers with heuristics
+# detect the operating system
+
+# Initially assume all OS detection values are for a container, these are moved later if we are bare-metal
+
+CONTAINER_OS_DETECTION="unknown"
+CONTAINER_NAME="unknown"
+CONTAINER_VERSION="unknown"
+CONTAINER_VERSION_ID="unknown"
+CONTAINER_ID="unknown"
+CONTAINER_ID_LIKE="unknown"
+
+if [ "${KERNEL_NAME}" = "Darwin" ]; then
+ CONTAINER_ID=$(sw_vers -productName)
+ CONTAINER_ID_LIKE="mac"
+ CONTAINER_NAME="mac"
+ CONTAINER_VERSION=$(sw_vers -productVersion)
+ CONTAINER_OS_DETECTION="sw_vers"
+elif [ "${KERNEL_NAME}" = "FreeBSD" ]; then
+ CONTAINER_ID="FreeBSD"
+ CONTAINER_ID_LIKE="FreeBSD"
+ CONTAINER_NAME="FreeBSD"
+ CONTAINER_OS_DETECTION="uname"
+ CONTAINER_VERSION=$(uname -r)
+ KERNEL_VERSION=$(uname -K)
+else
+ if [ -f "/etc/os-release" ]; then
+ eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" </etc/os-release | sed 's/^/CONTAINER_/')"
+ CONTAINER_OS_DETECTION="/etc/os-release"
+ fi
+
+ if [ "${NAME}" = "unknown" ] || [ "${VERSION}" = "unknown" ] || [ "${ID}" = "unknown" ]; then
+ if [ -f "/etc/lsb-release" ]; then
+ if [ "${OS_DETECTION}" = "unknown" ]; then
+ CONTAINER_OS_DETECTION="/etc/lsb-release"
+ else
+ CONTAINER_OS_DETECTION="Mixed"
+ fi
+ DISTRIB_ID="unknown"
+ DISTRIB_RELEASE="unknown"
+ DISTRIB_CODENAME="unknown"
+ eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" </etc/lsb-release)"
+ if [ "${NAME}" = "unknown" ]; then CONTAINER_NAME="${DISTRIB_ID}"; fi
+ if [ "${VERSION}" = "unknown" ]; then CONTAINER_VERSION="${DISTRIB_RELEASE}"; fi
+ if [ "${ID}" = "unknown" ]; then CONTAINER_ID="${DISTRIB_CODENAME}"; fi
+ fi
+ if [ -n "$(command -v lsb_release 2>/dev/null)" ]; then
+ if [ "${OS_DETECTION}" = "unknown" ]; then
+ CONTAINER_OS_DETECTION="lsb_release"
+ else
+ CONTAINER_OS_DETECTION="Mixed"
+ fi
+ if [ "${NAME}" = "unknown" ]; then CONTAINER_NAME="$(lsb_release -is 2>/dev/null)"; fi
+ if [ "${VERSION}" = "unknown" ]; then CONTAINER_VERSION="$(lsb_release -rs 2>/dev/null)"; fi
+ if [ "${ID}" = "unknown" ]; then CONTAINER_ID="$(lsb_release -cs 2>/dev/null)"; fi
+ fi
+ fi
+fi
+# If Netdata is not running in a container then use the local detection as the host
+HOST_OS_DETECTION="unknown"
+HOST_NAME="unknown"
+HOST_VERSION="unknown"
+HOST_VERSION_ID="unknown"
+HOST_ID="unknown"
+HOST_ID_LIKE="unknown"
if [ "${CONTAINER}" = "unknown" ]; then
- if [ -f /proc/1/sched ] ; then
- IFS='(, ' read -r process _ </proc/1/sched
- if [ "${process}" = "netdata" ]; then
- CONTAINER="container"
- CONT_DETECTION="process"
- fi
- fi
- # ubuntu and debian supply /bin/running-in-container
- # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
- if /bin/running-in-container >/dev/null 2>&1; then
- CONTAINER="container"
- CONT_DETECTION="/bin/running-in-container"
- fi
-
- # lxc sets environment variable 'container'
- #shellcheck disable=SC2154
- if [ -n "${container}" ]; then
- CONTAINER="lxc"
- CONT_DETECTION="containerenv"
- fi
-
- # docker creates /.dockerenv
- # http://stackoverflow.com/a/25518345
- if [ -f "/.dockerenv" ]; then
- CONTAINER="docker"
- CONT_DETECTION="dockerenv"
- fi
+ for v in NAME ID ID_LIKE VERSION VERSION_ID OS_DETECTION; do
+ eval "HOST_$v=\$CONTAINER_$v; CONTAINER_$v=none"
+ done
+else
+# Otherwise try and use a user-supplied bind-mount into the container to resolve the host details
+ if [ -e "/host/etc/os-release" ]; then
+ OS_DETECTION="/etc/os-release"
+ eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" </host/etc/os-release | sed 's/^/HOST_/')"
+ HOST_OS_DETECTION="/host/etc/os-release"
+ fi
+ if [ "${HOST_NAME}" = "unknown" ] || [ "${HOST_VERSION}" = "unknown" ] || [ "${HOST_ID}" = "unknown" ]; then
+ if [ -f "/host/etc/lsb-release" ]; then
+ if [ "${HOST_OS_DETECTION}" = "unknown" ]; then
+ HOST_OS_DETECTION="/etc/lsb-release"
+ else
+ HOST_OS_DETECTION="Mixed"
+ fi
+ DISTRIB_ID="unknown"
+ DISTRIB_RELEASE="unknown"
+ DISTRIB_CODENAME="unknown"
+ eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" </etc/lsb-release)"
+ if [ "${HOST_NAME}" = "unknown" ]; then HOST_NAME="${DISTRIB_ID}"; fi
+ if [ "${HOST_VERSION}" = "unknown" ]; then HOST_VERSION="${DISTRIB_RELEASE}"; fi
+ if [ "${HOST_ID}" = "unknown" ]; then HOST_ID="${DISTRIB_CODENAME}"; fi
+ fi
+ fi
fi
-echo "NETDATA_SYSTEM_OS_NAME=${NAME}"
-echo "NETDATA_SYSTEM_OS_ID=${ID}"
-echo "NETDATA_SYSTEM_OS_ID_LIKE=${ID_LIKE}"
-echo "NETDATA_SYSTEM_OS_VERSION=${VERSION}"
-echo "NETDATA_SYSTEM_OS_VERSION_ID=${VERSION_ID}"
-echo "NETDATA_SYSTEM_OS_DETECTION=${OS_DETECTION}"
+
+echo "NETDATA_CONTAINER_OS_NAME=${CONTAINER_NAME}"
+echo "NETDATA_CONTAINER_OS_ID=${CONTAINER_ID}"
+echo "NETDATA_CONTAINER_OS_ID_LIKE=${CONTAINER_ID_LIKE}"
+echo "NETDATA_CONTAINER_OS_VERSION=${CONTAINER_VERSION}"
+echo "NETDATA_CONTAINER_OS_VERSION_ID=${CONTAINER_VERSION_ID}"
+echo "NETDATA_CONTAINER_OS_DETECTION=${CONTAINER_OS_DETECTION}"
+echo "NETDATA_HOST_OS_NAME=${HOST_NAME}"
+echo "NETDATA_HOST_OS_ID=${HOST_ID}"
+echo "NETDATA_HOST_OS_ID_LIKE=${HOST_ID_LIKE}"
+echo "NETDATA_HOST_OS_VERSION=${HOST_VERSION}"
+echo "NETDATA_HOST_OS_VERSION_ID=${HOST_VERSION_ID}"
+echo "NETDATA_HOST_OS_DETECTION=${HOST_OS_DETECTION}"
echo "NETDATA_SYSTEM_KERNEL_NAME=${KERNEL_NAME}"
echo "NETDATA_SYSTEM_KERNEL_VERSION=${KERNEL_VERSION}"
echo "NETDATA_SYSTEM_ARCHITECTURE=${ARCHITECTURE}"
diff --git a/database/rrd.h b/database/rrd.h
index 40efd60e92..b873a5124d 100644
--- a/database/rrd.h
+++ b/database/rrd.h
@@ -618,12 +618,18 @@ typedef struct alarm_log {
// RRD HOST
struct rrdhost_system_info {
- char *os_name;
- char *os_id;
- char *os_id_like;
- char *os_version;
- char *os_version_id;
- char *os_detection;
+ char *host_os_name;
+ char *host_os_id;
+ char *host_os_id_like;
+ char *host_os_version;
+ char *host_os_version_id;
+ char *host_os_detection;
+ char *container_os_name;
+ char *container_os_id;
+ char *container_os_id_like;
+ char *container_os_version;
+ char *container_os_version_id;
+ char *container_os_detection;
char *kernel_name;
char *kernel_version;
char *architecture;
diff --git a/database/rrdhost.c b/database/rrdhost.c
index 5a4b195807..48bec95a21 100644
--- a/database/rrdhost.c
+++ b/database/rrdhost.c
@@ -563,12 +563,18 @@ void rrdhost_system_info_free(struct rrdhost_system_info *system_info) {
info("SYSTEM_INFO: free %p", system_info);
if(likely(system_info)) {
- freez(system_info->os_name);
- freez(system_info->os_id);
- freez(system_info->os_id_like);
- freez(system_info->os_version);
- freez(system_info->os_version_id);
- freez(system_info->os_detection);
+ freez(system_info->host_os_name);
+ freez(system_info->host_os_id);
+ freez(system_info->host_os_id_like);
+ freez(system_info->host_os_version);
+ freez(system_info->host_os_version_id);
+ freez(system_info->host_os_detection);
+ freez(system_info->container_os_name);
+ freez(system_info->container_os_id);
+ freez(system_info->container_os_id_like);
+ freez(system_info->container_os_version);
+ freez(system_info->container_os_version_id);
+ freez(system_info->container_os_detection);
freez(system_info->kernel_name);
freez(system_info->kernel_version);
freez(system_info->architecture);
@@ -762,13 +768,13 @@ struct label *load_auto_labels()
{
struct label *label_list = NULL;
- if (localhost->system_info->os_name)
+ if (localhost->system_info->host_os_name)
label_list =
- add_label_to_list(label_list, "_os_name", localhost->system_info->os_name, LABEL_SOURCE_AUTO);
+ add_label_to_list(label_list, "_os_name", localhost->system_info->host_os_name, LABEL_SOURCE_AUTO);
- if (localhost->system_info->os_version)
+ if (localhost->system_info->host_os_version)
label_list =
- add_label_to_list(label_list, "_os_version", localhost->system_info->os_version, LABEL_SOURCE_AUTO);
+ add_label_to_list(label_list, "_os_version", localhost->system_info->host_os_version, LABEL_SOURCE_AUTO);
if (localhost->system_info->kernel_version)
label_list =
@@ -782,9 +788,17 @@ struct label *load_auto_labels()
label_list =
add_label_to_list(label_list, "_virtualization", localhost->system_info->virtualization, LABEL_SOURCE_AUTO);
+ if (localhost->system_info->container)
+ label_list =
+ add_label_to_list(label_list, "_container", localhost->system_info->container, LABEL_SOURCE_AUTO);
+
+ if (localhost->system_info->container_detection)
+ label_list =
+ add_label_to_list(label_list, "_container_detection", localhost->system_info->container_detection, LABEL_SOURCE_AUTO);
+
if (localhost->system_info->virt_detection)
label_list =
- add_label_to_list(label_list, "_container", localhost->system_info->virt_detection, LABEL_SOURCE_AUTO);
+ add_label_to_list(label_list, "_virt_detection", localhost->system_info->virt_detection, LABEL_SOURCE_AUTO);
label_list = add_label_to_list(
label_list, "_is_master", (localhost->next || configured_as_master()) ? "true" : "false", LABEL_SOURCE_AUTO);
@@ -1115,29 +1129,53 @@ restart_after_removal:
int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value) {
int res = 0;
- if(!strcmp(name, "NETDATA_SYSTEM_OS_NAME")){
- freez(system_info->os_name);
- system_info->os_name = strdupz(value);
+ if(!strcmp(name, "NETDATA_CONTAINER_OS_NAME")){
+ freez(system_info->container_os_name);
+ system_info->container_os_name = strdupz(value);
+ }
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_ID")){
+ freez(system_info->container_os_id);
+ system_info->container_os_id = strdupz(value);
+ }
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_ID_LIKE")){
+ freez(system_info->container_os_id_like);
+ system_info->container_os_id_like = strdupz(value);
+ }
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_VERSION")){
+ freez(system_info->container_os_version);
+ system_info->container_os_version = strdupz(value);
+ }
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_VERSION_ID")){
+ freez(system_info->container_os_version_id);
+ system_info->container_os_version_id = strdupz(value);
+ }
+ else if(!strcmp(name, "NETDATA_CONTAINER_OS_DETECTION")){
+ freez(system_info->host_os_detection);
+ system_info->host_os_detection = strdupz(value);
+ }
+ else if(!strcmp(name, "NETDATA_HOST_OS_NAME")){
+ freez(system_info->host_os_name);
+ system_info->host_os_name = strdupz(value);
}
- else if(!strcmp(name, "NETDATA_SYSTEM_OS_ID")){
- freez(system_info->os_id);
- system_info->os_id = strdupz(value);
+ else if(!strcmp(name, "NETDATA_HOST_OS_ID")){
+ freez(system_info->host_os_id);
+ system_info->host_os_id = strdupz(value);
}
- else if(!strcmp(name, "NETDATA_SYSTEM_OS_ID_LIKE")){
- freez(system_info->os_id_like);
- system_info->os_id_like = strdupz(value);
+ else if(!strcmp(name, "NETDATA_HOST_OS_ID_LIKE")){
+ freez(system_info->host_os_id_like);
+ system_info->host_os_id_like = strdupz(value);
}
- else if(!strcmp(name, "NETDATA_SYSTEM_OS_VERSION")){
- freez(system_info->os_version);
- system_info->os_version = strdupz(value);
+ else if(!strcmp(name, "NETDATA_HOST_OS_VERSION")){
+ freez(system_info->host_os_version);
+ system_info->host_os_version = strdupz(value);
}
- else if(!strcmp(name, "NETDATA_SYSTEM_OS_VERSION_ID")){
- freez(system_info->os_version_id);
- system_info->os_version_id = strdupz(value);
+ else if(!strcmp(name, "NETDATA_HOST_OS_VERSION_ID")){
+ freez(system_info->host_os_version_id);
+ system_info->host_os_version_id = strdupz(value);
}
- else if(!strcmp(name, "NETDATA_SYSTEM_OS_DETECTION")){
- freez(system_info->os_detection);
- system_info->os_detection = strdupz(value);
+ else if(!strcmp(name, "NETDATA_HOST_OS_DETECTION")){
+ freez(system_info->host_os_detection);
+ system_info->host_os_detection = strdupz(value);
}
else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_NAME")){
freez(system_info->kernel_name);
diff --git a/packaging/docker/README.md b/packaging/docker/README.md
index 6ef3497234..2d09b0d8e6 100644
--- a/packaging/docker/README.md
+++ b/packaging/docker/README.md
@@ -35,6 +35,7 @@ docker run -d --name=netdata \
-v /etc/group:/host/etc/group:ro \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
+ -v /etc/os-release:/host/etc/os-release:ro \
--cap-add SYS_PTRACE \
--security-opt apparmor=unconfined \
netdata/netdata
@@ -61,8 +62,26 @@ services:
- /sys:/host/sys:ro
```
-If you don't want to use the apps.plugin functionality, you can remove the mounts of `/etc/passwd` and `/etc/group`
-(they are used to get proper user and group names for the monitored host) to get slightly better security.
+Some of the bind-mounts are optional depending on how you use Netdata:
+
+* If you don't want to use the apps.plugin functionality, you can remove the mounts of `/etc/passwd` and `/etc/group`
+ (they are used to get proper user and group names for the monitored host) to get slightly better security.
+
+* Most modern linux distos supply `/etc/os-release` although some older distros only supply `/etc/lsb-release`. If
+ this is the case you can change the line above that mounts the file inside the container to
+ `-v /etc/lsb-release:/host/etc/lsb-release:ro`.
+
+* If your host is virtualized then Netdata cannot detect it from inside the container and will output the wrong
+ metadata (e.g. on `/api/v1/info` queries). You can fix this by setting a variable that overrides the detection
+ using, e.g. `--env VIRTUALIZATION=$(systemd-detect-virt -v)`. If you are using a `docker-compose.yml` then add:
+```
+ environment:
+ - VIRTUALIZATION=${VIRTUALIZATION}
+```
+This allows the information to be passed into `docker-compose` using:
+```
+VIRTUALIZATION=$(systemd-detect-virt -v) docker-compose up
+```
Starting with v1.12, Netdata collects anonymous usage information by default and sends it to Google Analytics. Read
about the information collected, and learn how to-opt, on our [anonymous statistics](../../docs/anonymous-statistics.md)
diff --git a/streaming/rrdpush.c b/streaming/rrdpush.c
index c6c391e4b1..f110a4c92a 100644
--- a/streaming/rrdpush.c
+++ b/streaming/rrdpush.c
@@ -552,6 +552,9 @@ static int rrdpush_sender_thread_connect_to_master(RRDHOST *host, int default_po
}
#endif
+ /* TODO: During the implementation of #7265 switch the set of variables to HOST_* and CONTAINER_* if the
+ version negotiation resulted in a high enough version.
+ */
#define HTTP_HEADER_SIZE 8192
char http[HTTP_HEADER_SIZE + 1];
int eol = snprintfz(http, HTTP_HEADER_SIZE,
@@ -581,12 +584,12 @@ static int rrdpush_sender_thread_connect_to_master(RRDHOST *host, int default_po
, host->os
, host->timezone
, (host->tags) ? host->tags : ""
- , (host->system_info->os_name) ? host->system_info->os_name : ""
- , (host->system_info->os_id) ? host->system_info->os_id : ""
- , (host->system_info->os_id_like) ? host->system_info->os_id_like : ""
- , (host->system_info->os_version) ? host->system_info->os_version : ""
- , (host->system_info->os_version_id) ? host->system_info->os_version_id : ""
- , (host->system_info->os_detection) ? host->system_info->os_detection : ""
+ , (host->system_info->host_os_name) ? host->system_info->host_os_name : ""
+ , (host->system_info->host_os_id) ? host->system_info->host_os_id : ""
+ , (host->system_info->host_os_id_like) ? host->system_info->host_os_id_like : ""
+ , (host->system_info->host_os_version) ? host->system_info->host_os_version : ""
+ , (host->system_info->host_os_version_id) ? host->system_info->host_os_version_id : ""
+ , (host->system_info->host_os_detection) ? host->system_info->host_os_detection : ""
, (host->system_info->kernel_name) ? host->system_info->kernel_name : ""
, (host->system_info->kernel_version) ? host->system_info->kernel_version : ""
, (host->system_info->architecture) ? host->system_info->architecture : ""
@@ -1394,11 +1397,25 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
else {
if(!strcmp(name, "NETDATA_PROTOCOL_VERSION"))
stream_flags = LABEL_FLAG_UPDATE_STREAM;
- else
+ else {
+ // An old Netdata slave does not have a compatible streaming protocol, map to something sane.
+ if (!strcmp(name, "NETDATA_SYSTEM_OS_NAME"))
+ name = "NETDATA_HOST_OS_NAME";
+ else if (!strcmp(name, "NETDATA_SYSTEM_OS_ID"))
+ name = "NETDATA_HOST_OS_ID";
+ else if (!strcmp(name, "NETDATA_SYSTEM_OS_ID_LIKE"))
+ name = "NETDATA_HOST_OS_ID_LIKE";
+ else if (!strcmp(name, "NETDATA_SYSTEM_OS_VERSION"))
+ name = "NETDATA_HOST_OS_VERSION";
+ else if (!strcmp(name, "NETDATA_SYSTEM_OS_VERSION_ID"))
+ name = "NETDATA_HOST_OS_VERSION_ID";
+ else if (!strcmp(name, "NETDATA_SYSTEM_OS_DETECTION"))
+ name = "NETDATA_HOST_OS_DETECTION";
if (unlikely(rrdhost_set_system_info_variable(system_info, name, value))) {
info("STREAM [receive from [%s]:%s]: request has parameter '%s' = '%s', which is not used.",
w->client_ip, w->client_port, key, value);
}
+ }
}
}
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c
index afbf88b4d5..aafcbc70be 100644
--- a/web/api/web_api_v1.c
+++ b/web/api/web_api_v1.c
@@ -808,12 +808,26 @@ inline int web_client_api_request_v1_info(RRDHOST *host, struct web_client *w, c
web_client_api_request_v1_info_summary_alarm_statuses(host, wb);
buffer_strcat(wb, "\t},\n");
- buffer_sprintf(wb, "\t\"os_name\": \"%s\",\n", (host->system_info->os_name) ? host->system_info->os_name : "\"\"");
- buffer_sprintf(wb, "\t\"os_id\": \"%s\",\n", (host->system_info->os_id) ? host->system_info->os_id : "");
- buffer_sprintf(wb, "\t\"os_id_like\": \"%s\",\n", (host->system_info->os_id_like) ? host->system_info->os_id_like : "");
- buffer_sprintf(wb, "\t\"os_version\": \"%s\",\n", (host->system_info->os_version) ? host->system_info->os_version : "");
- buffer_sprintf(wb, "\t\"os_version_id\": \"%s\",\n", (host->system_info->os_version_id) ? host->system_info->os_version_id : "");
- buffer_sprintf(wb, "\t\"os_detection\": \"%s\",\n", (host->system_info->os_detection) ? host->system_info->os_detection : "");
+ buffer_sprintf(wb, "\t\"os_name\": \"%s\",\n", (host->system_info->host_os_name) ? host->system_info->host_os_name : "");
+ buffer_sprintf(wb, "\t\"os_id\": \"%s\",\n", (host->system_info->host_os_id) ? host->system_info->host_os_id : "");
+ buffer_sprintf(wb, "\t\"os_id_like\": \"%s\",\n", (host->system_info->host_os_id_like) ? host->system_info->host_os_id_like : "");
+ buffer_sprintf(wb, "\t\"os_version\": \"%s\",\n", (host->system_info->host_os_version) ? host->system_info->host_os_version : "");
+ buffer_sprintf(wb, "\t\"os_version_id\": \"%s\",\n", (host->system_info->host_os_version_id) ? host->system_info->host_os_version_id : "");
+ buffer_sprintf(wb, "\t\"os_detection\": \"%s\",\n", (host->system_info->host_os_detection) ? host->system_info->host_os_detection : "");
+
+ if (host->system_info->container_os_name)
+ buffer_sprintf(wb, "\t\"container_os_name\": \"%s\",\n", host->system_info->container_os_name);
+ if (host->system_info->container_os_id)
+ buffer_sprintf(wb, "\t\"container_os_id\": \"%s\",\n", host->system_info->container_os_id);
+ if (host->system_info->container_os_id_like)
+ buffer_sprintf(wb, "\t\"container_os_id_like\": \"%s\",\n", host->system_info->container_os_id_like);
+ if (host->system_info->container_os_version)
+ buffer_sprintf(wb, "\t\"container_os_version\": \"%s\",\n", host->system_info->container_os_version);
+ if (host->system_info->container_os_version_id)
+ buffer_sprintf(wb, "\t\"container_os_version_id\": \"%s\",\n", host->system_info->container_os_version_id);
+ if (host->system_info->container_os_detection)
+ buffer_sprintf(wb, "\t\"container_os_detection\": \"%s\",\n", host->system_info->container_os_detection);
+
buffer_sprintf(wb, "\t\"kernel_name\": \"%s\",\n", (host->system_info->kernel_name) ? host->system_info->kernel_name : "");
buffer_sprintf(wb, "\t\"kernel_version\": \"%s\",\n", (host->system_info->kernel_version) ? host->system_info->kernel_version : "");
buffer_sprintf(wb, "\t\"architecture\": \"%s\",\n", (host->system_info->architecture) ? host->system_info->architecture : "");