@cryptotaxi247 / netdata-1 / commits / d004f921d

Integrates the eBPF Kernel Collector with the NetData Installer (#8075)

* Initial Commit * Added a generic get() function that wraps either curl or wget and pipes the file to stdout * Added partial implementation of eBPF Kernel Collectpr * Move the kernel check inside should_install_ebpf() * Fixed shellcheck errors I missed * Fixed incorrect return in should_install_ebpf() * Refactored Kernel version parsing and LIBC Detection * Refactored Kernel / eBPF Package compatibility checks * Added a generic get() function that wraps either curl or wget and pipes the file to stdout * Added partial implementation of eBPF Kernel Collectpr * Move the kernel check inside should_install_ebpf() * Fixed shellcheck errors I missed * Fixed incorrect return in should_install_ebpf() * Refactored Kernel version parsing and LIBC Detection * Refactored Kernel / eBPF Package compatibility checks * Fixed bugs * Improve alignment of text output * Other minor fixes * Completed installation logic for eBPF Package * Missed libnetdata_ebpf.so * Fixed installation locaiton for libnetdata_ebpf.so * Added -f flag to ln so installs are idempotent * Refactored running check-kernel-config.sh * Use run to run the check-kernel.config.sh * Switch to grep + sed instead of jq * kernel_collector_integration: Fix problems with Fedora and other distributions that do not have '/usr' s default shared library directory * remove developer mode installation * kernel_collector_integration: Fix comparison Fixes comparison to get old kernel versions * Addressed @Ferroin's comments * Don't bother comparing kver to 0 Co-authored-by: thiagoftsm <thiagoftsm@gmail.com>

James Mills committed Feb 18, 2020 at 07:35 UTC d004f921d201cb49cc8e1d590f1d11aa753e1779
2 files changed +198 -14
netdata-installer.sh
+187 -14
@@ -27,8 +27,8 @@ fi
27
28 # -----------------------------------------------------------------------------
29 # Pull in OpenSSL properly if on macOS
30 -if [ "$(uname -s)" = 'Darwin' ] && [ -d /usr/local/opt/openssl/include ] ; then
31 - export C_INCLUDE_PATH="/usr/local/opt/openssl/include"
30 +if [ "$(uname -s)" = 'Darwin' ] && [ -d /usr/local/opt/openssl/include ]; then
31 + export C_INCLUDE_PATH="/usr/local/opt/openssl/include"
32 fi
33
34 # -----------------------------------------------------------------------------
@@ -169,6 +169,7 @@ USAGE: ${PROGRAM} [options]
169 --nightly-channel Use most recent nightly udpates instead of GitHub releases.
170 This results in more frequent updates.
171 --disable-go Disable installation of go.d.plugin.
172 + --enable-ebpf Enable eBPF Kernel plugin (Default: disabled, feature preview)
173 --disable-cloud Disable the agent-cloud link, required for Netdata Cloud functionality.
174 --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
175 --disable-plugin-freeipmi
@@ -254,7 +255,11 @@ while [ -n "${1}" ]; do
255 "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse" ;;
256 "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
257 "--disable-go") NETDATA_DISABLE_GO=1 ;;
257 - "--disable-cloud") NETDATA_DISABLE_LIBMOSQUITTO=1 ; NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-aclk/} --disable-aclk" ;;
258 + "--enable-ebpf") NETDATA_ENABLE_EBPF=1 ;;
259 + "--disable-cloud")
260 + NETDATA_DISABLE_LIBMOSQUITTO=1
261 + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-aclk/} --disable-aclk"
262 + ;;
263 "--install")
264 NETDATA_PREFIX="${2}/netdata"
265 shift 1
@@ -447,7 +452,7 @@ copy_libmosquitto() {
452 }
453
454 bundle_libmosquitto() {
450 - if [ -n "${NETDATA_DISABLE_LIBMOSQUITTO}" ] ; then
455 + if [ -n "${NETDATA_DISABLE_LIBMOSQUITTO}" ]; then
456 return 0
457 fi
458
@@ -470,7 +475,7 @@ bundle_libmosquitto() {
475 return 0
476 fi
477
473 - grep "${MOSQUITTO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" >"${tmp}/sha256sums.txt" 2>/dev/null
478 + grep "${MOSQUITTO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
479
480 cp packaging/mosquitto.checksums "${tmp}/sha256sums.txt"
481
@@ -902,8 +907,8 @@ govercomp() {
907 ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
908
909 local IFS=.
905 - read -ra ver1 <<<"$ver1"
906 - read -ra ver2 <<<"$ver2"
910 + read -ra ver1 <<< "$ver1"
911 + read -ra ver2 <<< "$ver2"
912
913 if [ ${#ver1[@]} -eq 0 ] || [ ${#ver2[@]} -eq 0 ]; then
914 return 3
@@ -929,14 +934,14 @@ should_install_go() {
934 local version_in_file
935 local binary_version
936
932 - version_in_file="$(cat packaging/go.d.version 2>/dev/null)"
933 - binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2>/dev/null)
937 + version_in_file="$(cat packaging/go.d.version 2> /dev/null)"
938 + binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2> /dev/null)
939
940 govercomp "$version_in_file" "$binary_version"
941 case $? in
937 - 0) return 1 ;; # =
938 - 2) return 1 ;; # <
939 - *) return 0 ;; # >, error
942 + 0) return 1 ;; # =
943 + 2) return 1 ;; # <
944 + *) return 0 ;; # >, error
945 esac
946 }
947
@@ -994,8 +999,8 @@ install_go() {
999 return 0
1000 fi
1001
997 - grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" >"${tmp}/sha256sums.txt" 2>/dev/null
998 - grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >>"${tmp}/sha256sums.txt" 2>/dev/null
1002 + grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
1003 + grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2> /dev/null
1004
1005 # Checksum validation
1006 if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
@@ -1026,6 +1031,174 @@ install_go() {
1031
1032 install_go
1033
1034 +function get_kernel_version() {
1035 + r="$(uname -r | cut -f 1 -d '-')"
1036 +
1037 + read -r -a p <<< "$(echo "${r}" | tr '.' ' ')"
1038 +
1039 + printf "%03d%03d%03d" "${p[0]}" "${p[1]}" "${p[2]}"
1040 +}
1041 +
1042 +detect_libc() {
1043 + libc=
1044 + if ldd --version 2>&1 | grep -q -i glibc; then
1045 + echo >&2 " Detected GLIBC"
1046 + libc="glibc"
1047 + elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
1048 + echo >&2 " Detected GLIBC"
1049 + libc="glibc"
1050 + elif ldd --version 2>&1 | grep -q -i musl; then
1051 + echo >&2 " Detected musl"
1052 + libc="musl"
1053 + else
1054 + echo >&2 " ERROR: Cannot detect a supported libc on your system!"
1055 + return 1
1056 + fi
1057 + echo "${libc}"
1058 + return 0
1059 +}
1060 +
1061 +get_compatible_kernel_for_ebpf() {
1062 + kver="${1}"
1063 +
1064 + # XXX: Logic taken from Slack discussion in #ebpf
1065 + # everything that has a version <= 4.14 can use the code built to 4.14
1066 + # Continue the logic, everything that has a version <= 4.19 and >= 4.15 can use the code built to 4.19
1067 + # Finally, everybody that is using 5.X can use what is compiled with 5.4
1068 +
1069 + kpkg=
1070 +
1071 + if [ "${kver}" -ge 005000000 ]; then
1072 + echo >&2 " Using eBPF Kernel Package built against Linux 5.4"
1073 + kpkg="5_4"
1074 + elif [ "${kver}" -ge 004015000 ] && [ "${kver}" -le 004020017 ]; then
1075 + echo >&2 " Using eBPF Kernel Package built against Linux 4.19"
1076 + kpkg="4_19"
1077 + elif [ "${kver}" -le 004014999 ]; then
1078 + echo >&2 " Using eBPF Kernel Package built against Linux 4.14"
1079 + kpkg="4_14"
1080 + else
1081 + echo >&2 " ERROR: Cannot detect a supported kernel on your system!"
1082 + return 1
1083 + fi
1084 +
1085 + echo "${kpkg}"
1086 + return 0
1087 +}
1088 +
1089 +should_install_ebpf() {
1090 + if [ "${NETDATA_ENABLE_EBPF:=0}" -ne 1 ]; then
1091 + run_failed "ebpf not enabled. --enable-ebpf to enable"
1092 + return 1
1093 + fi
1094 +
1095 + # Get and Parse Kernel Version
1096 + kver="$(get_kernel_version)"
1097 + kver="${kver:-0}"
1098 +
1099 + # Check Kernel Compatibility
1100 + if ! get_compatible_kernel_for_ebpf "${kver}" > /dev/null; then
1101 + echo >&2 " Detected Kernel: ${kver}"
1102 + run_failed "Kernel incompatible. Please contact NetData support!"
1103 + return 1
1104 + fi
1105 +
1106 + # Check Kernel Config
1107 +
1108 + tmp="$(mktemp -t -d netdata-ebpf-XXXXXX)"
1109 +
1110 + echo >&2 " Downloading check-kernel-config.sh ..."
1111 + if ! get "https://raw.githubusercontent.com/netdata/kernel-collector/master/tools/check-kernel-config.sh" > "${tmp}"/check-kernel-config.sh; then
1112 + run_failed "Failed to download check-kernel-config.sh"
1113 + echo 2>&" Removing temporary directory ${tmp} ..."
1114 + rm -rf "${tmp}"
1115 + return 1
1116 + fi
1117 +
1118 + run chmod +x "${tmp}"/check-kernel-config.sh
1119 +
1120 + if ! run "${tmp}"/check-kernel-config.sh; then
1121 + run_failed "Kernel unsupported or missing required config"
1122 + return 1
1123 + fi
1124 +
1125 + rm -rf "${tmp}"
1126 +
1127 + # TODO: Check for current vs. latest version
1128 +
1129 + return 0
1130 +}
1131 +
1132 +install_ebpf() {
1133 + if ! should_install_ebpf; then
1134 + return 0
1135 + fi
1136 +
1137 + progress "Installing eBPF plugin"
1138 +
1139 + # Get and Parse Kernel Version
1140 + kver="$(get_kernel_version)"
1141 + kver="${kver:-0}"
1142 +
1143 + # Get Compatible eBPF Kernel Package
1144 + kpkg="$(get_compatible_kernel_for_ebpf "${kver}")"
1145 +
1146 + # Detect libc
1147 + libc="$(detect_libc)"
1148 +
1149 + PACKAGE_TARBALL="netdata_ebpf-${kpkg}-${libc}.tar.xz"
1150 +
1151 + echo >&2 " Getting latest eBPF Package URL for ${PACKAGE_TARBALL} ..."
1152 +
1153 + PACKAGE_TARBALL_URL=
1154 + PACKAGE_TARBALL_URL="$(get "https://api.github.com/repos/netdata/kernel-collector/releases/latest" | grep -o -E "\"browser_download_url\": \".*${PACKAGE_TARBALL}\"" | sed -e 's/"browser_download_url": "\(.*\)"/\1/')"
1155 +
1156 + if [ -z "${PACKAGE_TARBALL_URL}" ]; then
1157 + run_failed "Could not get latest eBPF Package URL for ${PACKAGE_TARBALL}"
1158 + return 1
1159 + fi
1160 +
1161 + tmp="$(mktemp -t -d netdata-ebpf-XXXXXX)"
1162 +
1163 + echo >&2 " Downloading eBPF Package ${PACKAGE_TARBALL_URL} ..."
1164 + if ! get "${PACKAGE_TARBALL_URL}" > "${tmp}"/"${PACKAGE_TARBALL}"; then
1165 + run_failed "Failed to download latest eBPF Package ${PACKAGE_TARBALL_URL}"
1166 + echo 2>&" Removing temporary directory ${tmp} ..."
1167 + rm -rf "${tmp}"
1168 + return 1
1169 + fi
1170 +
1171 + echo >&2 " Extracting ${PACKAGE_TARBALL} ..."
1172 + tar -xf "${tmp}/${PACKAGE_TARBALL}" -C "${tmp}"
1173 +
1174 + echo >&2 " Finding suitable lib directory ..."
1175 + libdir=
1176 + libdir="$(ldconfig -v 2> /dev/null | grep ':$' | sed -e 's/://' | sort -r | grep 'usr' | head -n 1)"
1177 + if [ -z "${libdir}" ]; then
1178 + libdir="$(ldconfig -v 2> /dev/null | grep ':$' | sed -e 's/://' | sort -r | head -n 1)"
1179 + fi
1180 +
1181 + if [ -z "${libdir}" ]; then
1182 + run_failed "Could not find a suitable lib directory"
1183 + return 1
1184 + fi
1185 +
1186 + run cp -a -v "${tmp}/usr/lib64/libbpf_kernel.so" "${libdir}"
1187 + run cp -a -v "${tmp}/libnetdata_ebpf.so" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d"
1188 + run cp -a -v "${tmp}"/pnetdata_ebpf_process.o "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d"
1189 + run cp -a -v "${tmp}"/rnetdata_ebpf_process.o "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d"
1190 + run ln -v -f -s "${libdir}"/libbpf_kernel.so libbpf_kernel.so.0
1191 + run ldconfig
1192 +
1193 + echo >&2 "ePBF installation all done!"
1194 + rm -rf "${tmp}"
1195 +
1196 + return 0
1197 +}
1198 +
1199 +progress "eBPF Kernel Collector (opt-in)"
1200 +install_ebpf
1201 +
1202 # -----------------------------------------------------------------------------
1203 progress "Telemetry configuration"
1204
packaging/installer/functions.sh
+11
@@ -92,6 +92,17 @@ progress() {
92 echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
93 }
94
95 +get() {
96 + url="${1}"
97 + if command -v curl > /dev/null 2>&1; then
98 + curl -sSL -o - --connect-timeout 10 --retry 3 "${url}"
99 + elif command -v wget > /dev/null 2>&1; then
100 + wget -T 15 -O - "${url}"
101 + else
102 + fatal "I need curl or wget to proceed, but neither is available on this system."
103 + fi
104 +}
105 +
106 # -----------------------------------------------------------------------------
107
108 netdata_banner() {