Skip to content

Instantly share code, notes, and snippets.

@Atrate
Last active July 19, 2024 20:28
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
}'
@Atrate
Copy link
Author

Atrate commented Apr 1, 2024

@aquila0101 For your use-case, you'll need to change

    # 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])

to

    # Extract the download and upload values
    down[1] = $15
    down[2] = $16
    gsub(/[^a-zA-Z]/, "", down[2])
    up[1] = $18
    up[2] = $19
    gsub(/[^a-zA-Z]/, "", up[2])

I'll have to check on my server whether the log format just changed or whether for some reason yours is different than mine.

@Atrate
Copy link
Author

Atrate commented Apr 2, 2024

As far as I can see, my logs do not include the word "completed". I may have an older version of snowflake installed or something of that sort.

@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