summaryrefslogtreecommitdiffstats
path: root/collectors/tc.plugin/tc-qos-helper.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/tc.plugin/tc-qos-helper.sh.in')
-rwxr-xr-xcollectors/tc.plugin/tc-qos-helper.sh.in99
1 files changed, 79 insertions, 20 deletions
diff --git a/collectors/tc.plugin/tc-qos-helper.sh.in b/collectors/tc.plugin/tc-qos-helper.sh.in
index 0fab69eef..3298c39a3 100755
--- a/collectors/tc.plugin/tc-qos-helper.sh.in
+++ b/collectors/tc.plugin/tc-qos-helper.sh.in
@@ -2,54 +2,113 @@
# netdata
# real-time performance and health monitoring, done right!
-# (C) 2017 Costa Tsaousis <costa@tsaousis.gr>
+# (C) 2023 Netdata Inc.
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This script is a helper to allow netdata collect tc data.
# tc output parsing has been implemented in C, inside netdata
# This script allows setting names to dimensions.
-export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
+export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin:@sbindir_POST@"
export LC_ALL=C
+cmd_line="'${0}' $(printf "'%s' " "${@}")"
+
# -----------------------------------------------------------------------------
-# logging functions
+# logging
-PROGRAM_NAME="$(basename "$0")"
+PROGRAM_NAME="$(basename "${0}")"
PROGRAM_NAME="${PROGRAM_NAME/.plugin/}"
-logdate() {
- date "+%Y-%m-%d %H:%M:%S"
+# 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
}
-log() {
- local status="${1}"
- shift
+set_log_min_priority
- echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
+log() {
+ local level="${1}"
+ shift 1
+
+ [[ -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=tc-qos-helper
+ND_LOG_SOURCE=collector
+ND_REQUEST=${cmd_line}
+MESSAGE=${*//\\n/--NEWLINE--}
+
+EOFLOG
+ # AN EMPTY LINE IS NEEDED ABOVE
+}
+info() {
+ log "$NDLP_INFO" "${@}"
}
warning() {
- log WARNING "${@}"
+ log "$NDLP_WARN" "${@}"
}
error() {
- log ERROR "${@}"
-}
-
-info() {
- log INFO "${@}"
+ log "$NDLP_ERR" "${@}"
}
fatal() {
- log FATAL "${@}"
- exit 1
+ log "$NDLP_ALERT" "${@}"
+ exit 1
}
-debug=0
debug() {
- [ $debug -eq 1 ] && log DEBUG "${@}"
+ log "$NDLP_DEBUG" "${@}"
}
# -----------------------------------------------------------------------------