Skip to content

Instantly share code, notes, and snippets.

@Atrate
Last active April 2, 2024 19:02
Show Gist options
  • Save Atrate/be4a7d308549c7a9fe281d2cdf578d21 to your computer and use it in GitHub Desktop.
Save Atrate/be4a7d308549c7a9fe281d2cdf578d21 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 --posix
docker logs snowflake-proxy 2>&1 | grep --color=auto 'Traffic Relayed' | awk '
{
# Extract the download and upload values
down[1] = $14
down[2] = $15
gsub(/[^a-zA-Z]/, "", down[2])
up[1] = $17
up[2] = $18
gsub(/[^a-zA-Z]/, "", up[2])
# Convert to bytes
if (down[2] == "B") down_total += down[1];
else if (down[2] == "KB") down_total += down[1] * 1024;
else if (down[2] == "MB") down_total += down[1] * 1024 * 1024;
else if (down[2] == "GB") down_total += down[1] * 1024 * 1024 * 1024;
if (up[2] == "B") up_total += up[1];
else if (up[2] == "KB") up_total += up[1] * 1024;
else if (up[2] == "MB") up_total += up[1] * 1024 * 1024;
else if (up[2] == "GB") up_total += up[1] * 1024 * 1024 * 1024;
count++;
}
END {
print "Sum of down traffic on Snowflake: " down_total / 1024/ 1024 / 1024 " GB";
print "Sum of up traffic on Snowflake: " up_total / 1024 / 1024 / 1024 " GB";
print "Total connections established: " count
}'
@aquila0101
Copy link

now it's correct:
root@DietPi:~# ./snowstats.sh
Sum of down traffic on Snowflake: 69.8545 GB
Sum of up traffic on Snowflake: 3.73765 GB
Total connections established: 100

@aquila0101
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment