#!/usr/bin/env bash # SPDX-License-Identifier: GPL-3.0-or-later # netdata # real-time performance and health monitoring, done right! # (C) 2017 Costa Tsaousis # GPL v3+ # # This plugin requires a latest version of ioping. # You can compile it from source, by running me with option: install export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin:@sbindir_POST@" export LC_ALL=C usage="$(basename "$0") [install] [-h] [-e] where: install install ioping binary -e, --env path to environment file (defaults to '/etc/netdata/.environment' -h show this help text" INSTALL=0 ENVIRONMENT_FILE="/etc/netdata/.environment" while :; do case "$1" in -h | --help) echo "$usage" >&2 exit 1 ;; install) INSTALL=1 shift ;; -e | --env) ENVIRONMENT_FILE="$2" shift 2 ;; -*) echo "$usage" >&2 exit 1 ;; *) break ;; esac done if [ "$INSTALL" == "1" ] then [ "${UID}" != 0 ] && echo >&2 "Please run me as root. This will install a single binary file: /usr/libexec/netdata/plugins.d/ioping." && exit 1 source "${ENVIRONMENT_FILE}" || exit 1 run() { printf >&2 " > " printf >&2 "%q " "${@}" printf >&2 "\n" "${@}" || exit 1 } download() { local git="$(which git 2>/dev/null || command -v git 2>/dev/null)" [ ! -z "${git}" ] && run git clone "${1}" "${2}" && return 0 echo >&2 "Cannot find 'git' in this system." && exit 1 } tmp=$(mktemp -d /tmp/netdata-ioping-XXXXXX) [ ! -d "${NETDATA_PREFIX}/usr/libexec/netdata" ] && run mkdir -p "${NETDATA_PREFIX}/usr/libexec/netdata" run cd "${tmp}" if [ -d ioping-netdata ] then run rm -rf ioping-netdata || exit 1 fi download 'https://github.com/netdata/ioping.git' 'ioping-netdata' [ $? -ne 0 ] && exit 1 run cd ioping-netdata || exit 1 INSTALL_PATH="${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" run make clean run make run mv ioping "${INSTALL_PATH}" run chown root:"${NETDATA_GROUP}" "${INSTALL_PATH}" run chmod 4750 "${INSTALL_PATH}" echo >&2 echo >&2 "All done, you have a compatible ioping now at ${INSTALL_PATH}." echo >&2 exit 0 fi # ----------------------------------------------------------------------------- # logging PROGRAM_NAME="$(basename "${0}")" # these should be the same with syslog() priorities NDLP_EMERG=0 # system is unusable NDLP_ALERT=1 # action must be taken immediately NDLP_CRIT=2 # critical conditions NDLP_ERR=3 # error conditions NDLP_WARN=4 # warning conditions NDLP_NOTICE=5 # normal but significant condition NDLP_INFO=6 # informational NDLP_DEBUG=7 # debug-level messages # the max (numerically) log level we will log LOG_LEVEL=$NDLP_INFO set_log_min_priority() { case "${NETDATA_LOG_LEVEL,,}" in "emerg" | "emergency") LOG_LEVEL=$NDLP_EMERG ;; "alert") LOG_LEVEL=$NDLP_ALERT ;; "crit" | "critical") LOG_LEVEL=$NDLP_CRIT ;; "err" | "error") LOG_LEVEL=$NDLP_ERR ;; "warn" | "warning") LOG_LEVEL=$NDLP_WARN ;; "notice") LOG_LEVEL=$NDLP_NOTICE ;; "info") LOG_LEVEL=$NDLP_INFO ;; "debug") LOG_LEVEL=$NDLP_DEBUG ;; esac } set_log_min_priority log() { local level="${1}" shift 1 [[ -n "$level" && -n "$LOG_LEVEL" && "$level" -gt "$LOG_LEVEL" ]] && return systemd-cat-native --log-as-netdata --newline="--NEWLINE--" <