Permalink
Browse files

Fixe some typos in README. Add Some error handling. Fix a bug in the …

…template
  • Loading branch information...
1 parent f9aa742 commit 1315875a9d30bfd766f86ca22c66027d0efb7419 yann.malet@gmail.com committed with Mar 1, 2010
Showing with 92 additions and 77 deletions.
  1. +2 −2 README.rst
  2. +78 −73 varnishapp/templates/varnish/report.html
  3. +12 −2 varnishapp/views.py
View
@@ -15,14 +15,14 @@ Setup
-------
1. Install the `varnish python bindings <http://github.com/justquick/python-varnish>`_
2. Put ``varnishapp`` in your ``INSTALLED_APPS`` then set a few more settings.
-3. Add ``(^'admin/varnish/', include('varnishapp.urls')),`` to your urlconf
+3. Add ``(r'^admin/varnish/', include('varnishapp.urls')),`` to your urlconf
Configure
------------
``VARNISH_WATCHED_MODELS`` is a list of installed models whose absolute_urls you want to purge from your
Varnish cache upon saving. Example: ``('auth.user','profiles.profile')``
-``VARNISH_MANAGMENT_ADDRS`` is a list of Varnish cache addresses (containing their management ports).
+``VARNISH_MANAGEMENT_ADDRS`` is a list of Varnish cache addresses (containing their management ports).
Example ``('server1:6082','server2:6082')``
Management
@@ -5,78 +5,83 @@
<form><input type="text" name="command"/><input type="submit" value="Run command"/></form>
<table><tr>
- {% for server,report in stats %}
- <td><h1>{{ server|join:":" }}</h1>
- <blockquote>
- <h2>Client connections</h2>
- <ul>
- <li>Connections accepted {{ report.client_connections_accepted|intcomma }}</li>
- <li>Requests received {{ report.client_requests_received|intcomma }}</li>
- </ul>
-
- <h2>Cache utilization</h2>
- <ul>
- <li>Hits {{ report.cache_hits|intcomma }}</li>
- <li>Hits for pass {{ report.cache_hits_for_pass|intcomma }}</li>
- <li>Misses {{ report.cache_misses|intcomma }}</li>
- </ul>
-
- <h2>Backend connection usage</h2>
- <ul>
- <li>Successful {{ report.backend_connections_success|intcomma }}</li>
- <li>Recycled {{ report.backend_connections_recycles|intcomma }}</li>
- <li>Reused {{ report.backend_connections_reuses|intcomma }}</li>
- <li>Unused {{ report.backend_connections_unused|intcomma }}</li>
- <li>Not attempted {{ report.backend_connections_not_attempted|intcomma }}</li>
- <li>Failure {{ report.backend_connections_failures|intcomma }}</li>
- </ul>
-
- <ul>
- <li>N worker threads {{ report.n_worker_threads|intcomma }}</li>
- <li>N worker threads created {{ report.n_worker_threads_created|intcomma }}</li>
- <li>N worker threads not created {{ report.n_worker_threads_not_created|intcomma }}</li>
- <li>N worker threads limited {{ report.n_worker_threads_limited|intcomma }}</li>
- <li>N queued work requests {{ report.n_queued_work_requests|intcomma }}</li>
- <li>N overflowed work requests {{ report.n_overflowed_work_requests|intcomma }}</li>
- <li>N dropped work requests {{ report.n_dropped_work_requests|intcomma }}</li>
- </ul>
-
- <ul>
- <li>N expired objects {{ report.n_expired_objects|intcomma }}</li>
- <li>N objects on deathrow {{ report.n_objects_on_deathrow|intcomma }}</li>
- <li>HTTP header overflows {{ report.http_header_overflows|intcomma }}</li>
- <li>Objects sent with sendfile {{ report.objects_sent_with_sendfile|intcomma }}</li>
- <li>Objects sent with write {{ report.objects_sent_with_write|intcomma }}</li>
- </ul>
-
- <h2>Shared memory</h2>
- <ul>
- <li>Records {{ report.shm_records|intcomma }}</li>
- <li>Writes {{ report.shm_writes|intcomma }}</li>
- <li>MTX contention {{ report.shm_mtx_contention|intcomma }}</li>
- <li>Flushes do to overflow {{ report.shm_flushes_due_to_overflow|intcomma }}</li>
- <li>Cycles through buffer {{ report.shm_cycles_through_buffer|intcomma }}</li>
- </ul>
-
- <h2>Sessions</h2>
- <ul>
- <li>Closed {{ report.session_closed|intcomma }}</li>
- <li>Pipeline {{ report.session_pipeline|intcomma }}</li>
- <li>Read ahead {{ report.session_read_ahead|intcomma }}</li>
- <li>Herd {{ report.session_herd|intcomma }}</li>
- </ul>
-
- <h2>Totals</h2>
- <ul>
- <li>Sessions {{ report.total_sessions|intcomma }}</li>
- <li>Requests {{ report.total_requests|intcomma }}</li>
- <li>Pipe {{ report.total_pipe|intcomma }}</li>
- <li>Pass {{ report.total_pass|intcomma }}</li>
- <li>Fetch {{ report.total_fetch|intcomma }}</li>
- <li>Header bytes {{ report.total_header_bytes|intcomma }}</li>
- <li>Body bytes {{ report.total_body_bytes|intcomma }}</li>
- </ul>
- </blockquote></td>
- {% endfor %}
+ {% if stats %}
+ {% for server,report in stats %}
+ <td><h1>{{ server }}</h1>
+ <blockquote>
+ <h2>Client connections</h2>
+ <ul>
+ <li>Connections accepted {{ report.client_connections_accepted|intcomma }}</li>
+ <li>Requests received {{ report.client_requests_received|intcomma }}</li>
+ </ul>
+
+ <h2>Cache utilization</h2>
+ <ul>
+ <li>Hits {{ report.cache_hits|intcomma }}</li>
+ <li>Hits for pass {{ report.cache_hits_for_pass|intcomma }}</li>
+ <li>Misses {{ report.cache_misses|intcomma }}</li>
+ </ul>
+
+ <h2>Backend connection usage</h2>
+ <ul>
+ <li>Successful {{ report.backend_connections_success|intcomma }}</li>
+ <li>Recycled {{ report.backend_connections_recycles|intcomma }}</li>
+ <li>Reused {{ report.backend_connections_reuses|intcomma }}</li>
+ <li>Unused {{ report.backend_connections_unused|intcomma }}</li>
+ <li>Not attempted {{ report.backend_connections_not_attempted|intcomma }}</li>
+ <li>Failure {{ report.backend_connections_failures|intcomma }}</li>
+ </ul>
+
+ <ul>
+ <li>N worker threads {{ report.n_worker_threads|intcomma }}</li>
+ <li>N worker threads created {{ report.n_worker_threads_created|intcomma }}</li>
+ <li>N worker threads not created {{ report.n_worker_threads_not_created|intcomma }}</li>
+ <li>N worker threads limited {{ report.n_worker_threads_limited|intcomma }}</li>
+ <li>N queued work requests {{ report.n_queued_work_requests|intcomma }}</li>
+ <li>N overflowed work requests {{ report.n_overflowed_work_requests|intcomma }}</li>
+ <li>N dropped work requests {{ report.n_dropped_work_requests|intcomma }}</li>
+ </ul>
+
+ <ul>
+ <li>N expired objects {{ report.n_expired_objects|intcomma }}</li>
+ <li>N objects on deathrow {{ report.n_objects_on_deathrow|intcomma }}</li>
+ <li>HTTP header overflows {{ report.http_header_overflows|intcomma }}</li>
+ <li>Objects sent with sendfile {{ report.objects_sent_with_sendfile|intcomma }}</li>
+ <li>Objects sent with write {{ report.objects_sent_with_write|intcomma }}</li>
+ </ul>
+
+ <h2>Shared memory</h2>
+ <ul>
+ <li>Records {{ report.shm_records|intcomma }}</li>
+ <li>Writes {{ report.shm_writes|intcomma }}</li>
+ <li>MTX contention {{ report.shm_mtx_contention|intcomma }}</li>
+ <li>Flushes do to overflow {{ report.shm_flushes_due_to_overflow|intcomma }}</li>
+ <li>Cycles through buffer {{ report.shm_cycles_through_buffer|intcomma }}</li>
+ </ul>
+
+ <h2>Sessions</h2>
+ <ul>
+ <li>Closed {{ report.session_closed|intcomma }}</li>
+ <li>Pipeline {{ report.session_pipeline|intcomma }}</li>
+ <li>Read ahead {{ report.session_read_ahead|intcomma }}</li>
+ <li>Herd {{ report.session_herd|intcomma }}</li>
+ </ul>
+
+ <h2>Totals</h2>
+ <ul>
+ <li>Sessions {{ report.total_sessions|intcomma }}</li>
+ <li>Requests {{ report.total_requests|intcomma }}</li>
+ <li>Pipe {{ report.total_pipe|intcomma }}</li>
+ <li>Pass {{ report.total_pass|intcomma }}</li>
+ <li>Fetch {{ report.total_fetch|intcomma }}</li>
+ <li>Header bytes {{ report.total_header_bytes|intcomma }}</li>
+ <li>Body bytes {{ report.total_body_bytes|intcomma }}</li>
+ </ul>
+ </blockquote></td>
+ {% endfor %}
+ {% else %}
+ <h2>Stats Error</h2>
+ {{ errors.stats }}
+ {% endif %}
</tr></table>
{% endblock %}
View
@@ -7,11 +7,21 @@ def get_stats():
stats = [x[0] for x in manager.run('stats')]
return zip(getattr(settings, 'VARNISH_MANAGEMENT_ADDRS', ()), stats)
-def management(request):
+def management(request):
if not request.user.is_superuser:
return HttpResponseRedirect('/admin/')
if 'command' in request.REQUEST:
kwargs = dict(request.REQUEST.items())
manager.run(*str(kwargs.pop('command')).split(), **kwargs)
return HttpResponseRedirect(request.path)
- return direct_to_template(request, template='varnish/report.html', extra_context={'stats':get_stats})
+ try:
+ stats = get_stats()
+ except Exception as e:
+ stats = None
+ errors = {"stats":"Impossible to access the stats for server : %s" \
+ %getattr(settings, 'VARNISH_MANAGEMENT_ADDRS', ())}
+
+ extra_context = {'stats':stats,
+ 'errors':errors}
+ return direct_to_template(request, template='varnish/report.html',
+ extra_context=extra_context)

0 comments on commit 1315875

Please sign in to comment.