diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-11-22 21:47:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 23:47:55 +0200 |
commit | 5230b15f59fdd47efae668e5ac0c4ca042186e26 (patch) | |
tree | fc528fd576f6a20a0ec1d91d7ba45767ddcd477b /collectors/tc.plugin | |
parent | ae733dd494a1f497f5d6bdd0dd1e237f71e91cd9 (diff) |
fixes for logging (#16459)
* fixes for logging
* added log environment variables to cgroup-network
* fix wrong condition
* rename variable
* fix leftovers
* fix log2journal docs and logs
Diffstat (limited to 'collectors/tc.plugin')
-rwxr-xr-x | collectors/tc.plugin/tc-qos-helper.sh.in | 99 |
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 0fab69eeff..3298c39a30 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" "${@}" } # ----------------------------------------------------------------------------- |