From e6ab839098d87332af7ea7980bb1fe8fd439e58d Mon Sep 17 00:00:00 2001 From: Brian Candler Date: Thu, 16 Dec 2021 17:23:02 +0000 Subject: [PATCH] Add node_os_info.sh collector Signed-off-by: Brian Candler --- node_os_info.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 node_os_info.sh diff --git a/node_os_info.sh b/node_os_info.sh new file mode 100755 index 0000000..ecb2e6b --- /dev/null +++ b/node_os_info.sh @@ -0,0 +1,58 @@ +#!/bin/sh -e + +# Generate node_os_info and node_os_version metrics on legacy systems +# which are not handled by node_exporter's own collector +# (e.g. CentOS 6) + +[ -f /etc/os-release ] && exit 0 +[ -f /usr/lib/os-release ] && exit 0 + +ID="" +ID_LIKE="" +NAME="" +PRETTY_NAME="" +VERSION="" +VERSION_CODENAME="" +VERSION_ID="" +VERSION_METRIC="" + +if [ -f /etc/redhat-release ]; then + # CentOS release 6.10 (Final) + PRETTY_NAME="$(cat /etc/redhat-release)" + if [ -f /etc/centos-release ]; then + ID="centos" + elif [ -f /etc/oracle-release ]; then + ID="ol" + fi + ID_LIKE="rhel fedora" + NAME="$(expr "$PRETTY_NAME" : '\([^ ]*\)')" || true + VERSION="$(expr "$PRETTY_NAME" : '.* \([0-9].*\)')" || true + VERSION_ID="$(expr "$PRETTY_NAME" : '.* \([0-9][0-9.]*\)')" || true + # metric cannot distinguish 6.1 from 6.10, so only keep the integer part + VERSION_METRIC="$(expr "$VERSION_ID" : '\([0-9]*\)')" || true +elif [ -f /etc/lsb-release ]; then + # DISTRIB_ID=Ubuntu + # DISTRIB_RELEASE=12.04 + # DISTRIB_CODENAME=precise + # DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS" + # Beware, old versions of CentOS with package "redhat-lsb-core" look like this instead: + # LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch + + # shellcheck disable=SC1091 + . /etc/lsb-release + ID="$(echo "${DISTRIB_ID}" | tr '[:upper:]' '[:lower:]')" + NAME="${DISTRIB_ID}" + PRETTY_NAME="${DISTRIB_DESCRIPTION}" + VERSION="${DISTRIB_RELEASE} (${DISTRIB_CODENAME})" + VERSION_CODENAME="${DISTRIB_CODENAME}" + VERSION_ID="${DISTRIB_RELEASE}" + # 12.04.1 -> 12.04 + VERSION_METRIC="$(expr "$VERSION_ID" : '\([0-9]*\|[0-9]*\.[0-9]*\)')" || true +fi + +[ "$VERSION_METRIC" = "" ] && VERSION_METRIC="0" + +cat <