#!/usr/bin/env bash # netdata # real-time performance and health monitoring, done right! # (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:@sbindir_POST@" export LC_ALL=C cmd_line="'${0}' $(printf "'%s' " "${@}")" # ----------------------------------------------------------------------------- # logging PROGRAM_NAME="$(basename "${0}")" PROGRAM_NAME="${PROGRAM_NAME/.plugin/}" # 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--" </dev/null)" [ -n "${l}" ] && tc_devices="${tc_devices} ${dev}" done } # update devices and class names # once every 2 minutes names_every=$((qos_get_class_names_every / update_every)) # exit this script every hour # it will be restarted automatically exit_after=$((qos_exit_every / update_every)) c=0 gc=0 while true; do fix_names= c=$((c + 1)) gc=$((gc + 1)) if [ ${c} -le 1 ] || [ ${c} -ge ${names_every} ]; then c=1 fix_names="YES" find_tc_devices fi for d in ${tc_devices}; do show_tc "${d}" done echo "WORKTIME ${LOOPSLEEPMS_LASTWORK}" || exit loopsleepms "${update_every}" [ ${gc} -gt ${exit_after} ] && exit 0 done