0

Is it possible to produce a list or log of the bandwidth usage by file on NGINX? Something like:

BANDWIDTH USAGE LAST 7 DAYS by FILE;

\Project.zip 1.8 GB
\Docu8ment.doc 350 MB
\logo.png 238 MB
\style.css 72 MB
Michael Rogers
  • 60
  • 1
  • 3
  • 16

2 Answers2

0

Maybe something like this will work if you use it in a crontab ?

cd /rootDir/ for FILE in *; do

count=$(grep -c $FILE /var/log/nginx/access.log)

size=$(du $FILE | cut -f1)

BW4File=$((count * size))

echo $FILE $BW4File"K"

done

MeMow
  • 292
  • 1
  • 7
  • I found out why awstats and goaccess wouldn't work for me. The bytes are entirely missing from the log. Because downloads are started using nginx header X-Accel-Redirect there must be an issue somewhere else. but i'll award you for replying even though i can't test it. – Michael Rogers Dec 30 '20 at 14:22
  • Thanks man! I hope you get to test it. It calculates the size of yout files using du and multiplies it by the number of times it has been requested. It worked for me – MeMow Dec 30 '20 at 19:34
0

nginx produces access.log files with common log format. Common log format files can be analysed with different utilities, for example Webalizer and AWStats.

Those can generate statistics that you are looking for.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63