Django - How to measure bandwidth usage on static content?

I understand that this is more of a server issue (since all media requests bypass Django through NGINX), but I want to know how other Django developers do it, especially since I only need to understand the specifics of how to do this in NGINX. I'm not interested in the throughput of HTML page requests via Django; only bandwidth of static media files. Are you using this using Django and its DB, or are you using web server methods to do this? If so, I will move on to ServerFault .

I want to do this in order to measure bandwidth usage based on each subdomain (or similar method).

+3
source share
1 answer

Sorry for the non-django approach, but since we are talking about static files that in good practice will go without any kind of wsgi or whathaveyou hit.

Apache access logs have a request size in them, so you can make grep from your media files and directories (cat access_log | grep) / images / \ | media / thumbs / \ | jpg) and parse / sum this number with regexp and / or awk . Here is an example of an access log entry (45101 - file size):

10.0.0.123 - - [09 / Sep / 2010: 13: 30: 05 -0400] "GET /media/images/mypic.jpg HTTP / 1.1" 200 45101 "http://10.0.0.123/myapp" "Mozilla / 5.0 (Windows; U; Windows
NT 5.1; en-US; rv: 1.9.1.11) Gecko / 20100701 Firefox / 3.5.11 "

That should make you go.

+3

Source: https://habr.com/ru/post/1764039/


All Articles