diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:22 +0000 |
commit | c21c3b0befeb46a51b6bf3758ffa30813bea0ff0 (patch) | |
tree | 9754ff1ca740f6346cf8483ec915d4054bc5da2d /collectors/ioping.plugin/ioping.plugin.in | |
parent | Adding upstream version 1.43.2. (diff) | |
download | netdata-upstream/1.44.3.tar.xz netdata-upstream/1.44.3.zip |
Adding upstream version 1.44.3.upstream/1.44.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/ioping.plugin/ioping.plugin.in')
-rwxr-xr-x | collectors/ioping.plugin/ioping.plugin.in | 120 |
1 files changed, 82 insertions, 38 deletions
diff --git a/collectors/ioping.plugin/ioping.plugin.in b/collectors/ioping.plugin/ioping.plugin.in index d1283bad..171e384d 100755 --- a/collectors/ioping.plugin/ioping.plugin.in +++ b/collectors/ioping.plugin/ioping.plugin.in @@ -9,7 +9,7 @@ # 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" +export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin:@sbindir_POST@" export LC_ALL=C usage="$(basename "$0") [install] [-h] [-e] @@ -93,60 +93,103 @@ if [ "$INSTALL" == "1" ] fi # ----------------------------------------------------------------------------- +# logging PROGRAM_NAME="$(basename "${0}")" -LOG_LEVEL_ERR=1 -LOG_LEVEL_WARN=2 -LOG_LEVEL_INFO=3 -LOG_LEVEL="$LOG_LEVEL_INFO" - -set_log_severity_level() { - case ${NETDATA_LOG_SEVERITY_LEVEL,,} in - "info") LOG_LEVEL="$LOG_LEVEL_INFO";; - "warn" | "warning") LOG_LEVEL="$LOG_LEVEL_WARN";; - "err" | "error") LOG_LEVEL="$LOG_LEVEL_ERR";; +# 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_severity_level - -logdate() { - date "+%Y-%m-%d %H:%M:%S" -} +set_log_min_priority log() { - local status="${1}" - shift + local level="${1}" + shift 1 - echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}" + [[ -n "$level" && -n "$LOG_LEVEL" && "$level" -gt "$LOG_LEVEL" ]] && return + systemd-cat-native --log-as-netdata --newline="--NEWLINE--" <<EOFLOG +INVOCATION_ID=${NETDATA_INVOCATION_ID} +SYSLOG_IDENTIFIER=${PROGRAM_NAME} +PRIORITY=${level} +THREAD_TAG=ioping.plugin +ND_LOG_SOURCE=collector +MESSAGE=${MODULE_NAME}: ${*//\\n/--NEWLINE--} + +EOFLOG + # AN EMPTY LINE IS NEEDED ABOVE } info() { - [[ -n "$LOG_LEVEL" && "$LOG_LEVEL_INFO" -gt "$LOG_LEVEL" ]] && return - log INFO "${@}" + log "$NDLP_INFO" "${@}" } warning() { - [[ -n "$LOG_LEVEL" && "$LOG_LEVEL_WARN" -gt "$LOG_LEVEL" ]] && return - log WARNING "${@}" + log "$NDLP_WARN" "${@}" } error() { - [[ -n "$LOG_LEVEL" && "$LOG_LEVEL_ERR" -gt "$LOG_LEVEL" ]] && return - log ERROR "${@}" + log "$NDLP_ERR" "${@}" } -fatal() { - log FATAL "${@}" +disable() { + log "${@}" echo "DISABLE" - exit 1 + exit 1 +} + +fatal() { + disable "$NDLP_ALERT" "${@}" } -debug=0 debug() { - [ $debug -eq 1 ] && log DEBUG "${@}" + log "$NDLP_DEBUG" "${@}" } # ----------------------------------------------------------------------------- @@ -194,35 +237,36 @@ ioping_opts="-T 1000000" for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/${plugin}.conf" "${NETDATA_USER_CONFIG_DIR}/${plugin}.conf"; do if [ -f "${CONFIG}" ]; then - info "Loading config file '${CONFIG}'..." + debug "Loading config file '${CONFIG}'..." source "${CONFIG}" - [ $? -ne 0 ] && error "Failed to load config file '${CONFIG}'." + [ $? -ne 0 ] && warn "Failed to load config file '${CONFIG}'." elif [[ $CONFIG =~ ^$NETDATA_USER_CONFIG_DIR ]]; then - warning "Cannot find file '${CONFIG}'." + debug "Cannot find file '${CONFIG}'." fi done if [ -z "${destination}" ] then - fatal "destination is not configured - nothing to do." + disable $NDLP_DEBUG "destination is not configured - nothing to do." fi if [ ! -f "${ioping}" ] then - fatal "ioping command is not found. Please set its full path in '${NETDATA_USER_CONFIG_DIR}/${plugin}.conf'" + disable $NDLP_ERR "ioping command is not found. Please set its full path in '${NETDATA_USER_CONFIG_DIR}/${plugin}.conf'" fi if [ ! -x "${ioping}" ] then - fatal "ioping command '${ioping}' is not executable - cannot proceed." + disable $NDLP_ERR "ioping command '${ioping}' is not executable - cannot proceed." fi # the ioping options we will use options=( -N -i ${update_every} -s ${request_size} ${ioping_opts} ${destination} ) # execute ioping -info "starting ioping: ${ioping} ${options[*]}" +debug "starting ioping: ${ioping} ${options[*]}" + exec "${ioping}" "${options[@]}" # if we cannot execute ioping, stop -fatal "command '${ioping} ${options[*]}' failed to be executed (returned code $?)." +error "command '${ioping} ${options[*]}' failed to be executed (returned code $?)." |