From 955a4585f1360d3cfcc3b5008ed7737b54763919 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Sat, 12 Apr 2025 19:16:56 +0200 Subject: [PATCH] =?UTF-8?q?SnowflakeTraffic.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SnowflakeTraffic.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 SnowflakeTraffic.sh diff --git a/SnowflakeTraffic.sh b/SnowflakeTraffic.sh new file mode 100644 index 0000000..a1b1cbd --- /dev/null +++ b/SnowflakeTraffic.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +docker logs snowflake-proxy 2>&1 | awk ' +function human_readable(kb, units, size, i) { + split("KB MB GB TB PB", units) + size = kb + for (i = 1; size >= 1024 && i < 5; i++) { + size = size / 1024 + } + return sprintf("%.2f %s", size, units[i]) +} + +{ + # Datumserkennung und Formatierung + if (split($1, date_part, "/") == 3) { + current_date = $1 + gsub(/\//, "-", current_date) # Ersetze / durch - + if (!first_date) first_date = current_date + last_date = current_date + } +} + +/Traffic Relayed ↓ [0-9]+ KB .*↑ [0-9]+ KB/ { + for (i = 1; i <= NF; i++) { + if ($i == "↓") { down += $(i+1) } + if ($i == "↑") { up += $(i+1) } + } +} + +END { + printf "Statistik-Zeitraum:\n" + printf "Erster Eintrag: %s\n", first_date + printf "Letzter Eintrag: %s\n\n", last_date + + printf "Gesamte Datenmengen:\n" + printf "Download: %d KB (%s)\n", down, human_readable(down) + printf "Upload: %d KB (%s)\n", up, human_readable(up) +}' \ No newline at end of file