3

I realize this is more of a server question (since all media requests bypass Django via NGINX), but I want to know how others Django Developers have been doing this, more so than I care to understand only the specifics of how to do it in NGINX. I don't care about the bandwidth of HTML page requests via Django; only the bandwidth of static media files. Are those of you out there using Django and its DB to do this, or are you using web server-specific methods to do this? If the latter is the case, I'll head over to ServerFault.

I want to do this so I can measure the bandwidth usage on a per-subdomain (or similar method) basis.

orokusaki
  • 55,146
  • 59
  • 179
  • 257
  • Is caching not an option? Or are you already doing that? – Andrew Sledge Sep 09 '10 at 17:37
  • 1
    @Andrew - I don't understand. How would caching help me measure bandwidth usage, and why would I cache static files? – orokusaki Sep 09 '10 at 17:41
  • My apologies: I skipped the last sentence. AFAIK there isn't a measurement tool, at least not in the HTTPResponse object. – Andrew Sledge Sep 09 '10 at 17:46
  • @Andrew - To get that, I can just measure the `len(response)` and figure out how many bytes it is. I'm more interested in measuring the bandwidth of static files. I know it probably won't happen from within Django, but am curious as to how other Django devs are doing it. – orokusaki Sep 09 '10 at 18:24

1 Answers1

3

Sorry about non-django approach but as we speak about static files that in good practice get passed through without ever hitting the wsgi or whathaveyou.

Apache access logs have request size in them, so what you could do is grep out your media files and directories (cat access_log|grep "/images/\|/media/thumbs/\|jpg) and parse/sum that number with regexp and/or awk. Here's example access log entry (45101 being the 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 get you going..

Community
  • 1
  • 1
dsomnus
  • 1,391
  • 14
  • 21