traffic-peak-monitor.sh: right-align peak rate and percentage values in log output using fixed-width printf formatting (supports up to 1000 Mbit/s lines)

This commit is contained in:
2026-08-04 00:21:34 +02:00
parent 148a1f7295
commit 5b0cc8591a
+14 -2
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# #
# traffic-peak-monitor.sh # traffic-peak-monitor.sh
# ------------------------ # ------------------------
@@ -147,7 +147,19 @@ run_worker() {
# Log-Datei schreiben. Wichtig: das muss VOR einer moeglichen # Log-Datei schreiben. Wichtig: das muss VOR einer moeglichen
# Tages-Rotation passieren, da dieser Eintrag noch zu CUR_DAY # Tages-Rotation passieren, da dieser Eintrag noch zu CUR_DAY
# gehoert (z.B. der Eintrag "23:00-00:00" gehoert noch zum alten Tag). # gehoert (z.B. der Eintrag "23:00-00:00" gehoert noch zum alten Tag).
echo "${HOUR_START}-${HOUR_END} peak_rx=${MAX_RX_KBIT}kbit/s (${RX_PCT}%) peak_tx=${MAX_TX_KBIT}kbit/s (${TX_PCT}%)" >> "$log_file" #
# Feste Feldbreiten fuer eine sauber ausgerichtete Ausgabe:
# %7d -> kbit/s-Wert, rechtsbuendig, 7 Stellen breit.
# 7 Stellen reichen bis 9.999.999 kbit/s (= 9999 Mbit/s),
# deckt also auch 1000-Mbit/s-Leitungen (max. 1.000.000
# kbit/s = 7-stellig) komfortabel ab.
# %5.1f -> Prozentwert, rechtsbuendig, 1 Nachkommastelle,
# 5 Stellen breit (deckt bis "100.0" ab).
# Durch die feste Breite des peak_rx-Blocks beginnt "peak_tx="
# in jeder Zeile automatisch an derselben Spalte (linksbuendig),
# unabhaengig davon wie gross die einzelnen Zahlen sind.
printf '%s peak_rx=%7dkbit/s (%5.1f%%) peak_tx=%7dkbit/s (%5.1f%%)\n' \
"${HOUR_START}-${HOUR_END}" "$MAX_RX_KBIT" "$RX_PCT" "$MAX_TX_KBIT" "$TX_PCT" >> "$log_file"
MAX_RX=0 MAX_RX=0
MAX_TX=0 MAX_TX=0