Skip to content

Instantly share code, notes, and snippets.

@ckowarzik
Forked from Atrate/snowstats.sh
Last active September 16, 2024 14:08
Show Gist options
  • Save ckowarzik/f87913ddc414cf1bee341d31662e6cde to your computer and use it in GitHub Desktop.
Save ckowarzik/f87913ddc414cf1bee341d31662e6cde to your computer and use it in GitHub Desktop.
Quick script to get the statistics of traffic on Tor Project's Snowflake proxy instance running locally on docker
#!/bin/bash
# docker logs example:
# 2023/12/30 19:37:09 In the last 1h0m0s, there were 62 connections. Traffic Relayed ↑ 1321997 KB, ↓ 165777 KB.
docker logs snowflake-proxy 2>&1 \
| grep "Traffic Relayed" \
| sed 's|^\(20[0-9]\{2\}/[0-9]\{2\}/[0-9]\{2\}\) .* there were \([0-9]\+\) connections. Traffic Relayed . \([0-9]\+\) \([KMG]\?B\), . \([0-9]\+\) \([KMG]\?B\).$|\1 \2 \3 \4 \5 \6|' \
| awk '
BEGIN {
print "date\t\toutbound\tinbound\t\tconnections";
}
{
if (date > "" && date != $1) {
print $1 "\t" dout / 1024 / 1024 / 1024 " GB\t" din / 1024 / 1024 / 1024 " GB\t" dcount;
tout+=dout;
tin+=din;
tcount+=dcount;
dcount=0;
}
date=$1;
dcount+=$2;
if ($4 == "B") dout+= $3;
else if ($4 == "KB") dout+= $3 * 1024;
else if ($4 == "MB") dout+= $3 * 1024 * 1024;
else if ($4 == "GB") dout+= $3 * 1024 * 1024 * 1024;
if ($6 == "B") din+= $3;
else if ($6 == "KB") din+= $3 * 1024;
else if ($6 == "MB") din+= $3 * 1024 * 1024;
else if ($6 == "GB") din+= $3 * 1024 * 1024 * 1024;
}
END {
print "\nTOTAL\t\toutbound\tinbound\t\tconnections";
print "\t\t" tout / 1024 / 1024 / 1024 " GB\t" tin / 1024 / 1024 / 1024 " GB\t" tcount;
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment