Permalink
Browse files

new feature to email admins if the page takes longer than DUMPSLOW_EM…

…AIL_REQUEST_TIME to render. Disabled by default
  • Loading branch information...
1 parent a55acf1 commit 2d2c17d3aeea3526e658737df29af07a1b9a6b9a Nick Sullivan committed with Oct 27, 2011
Showing with 8 additions and 0 deletions.
  1. +6 −0 django_dumpslow/middleware.py
  2. +2 −0 django_dumpslow_example/settings.py
@@ -19,6 +19,7 @@
import threading
from django.conf import settings
+from django.core.mail import mail_admins
from django_dumpslow.utils import parse_interval
@@ -74,4 +75,9 @@ def process_response(self, request, response):
int(time.time()) - delete_after,
)
+ # If it was really slow, email admins. Disabled by default.
+ email_threshold = getattr(settings, 'DUMPSLOW_EMAIL_REQUEST_TIME', -1)
+ if email_threshold > -1 and time_taken > email_threshold:
+ mail_admins("SLOW PAGE: %s" % request.path, "This page took %2.2f seconds to render, which is over the threshold of %s.\n\n%s" % (time_taken, email_threshold, str(request)) )
+
return response
@@ -89,6 +89,8 @@
# How long a request has to take to be considered too long. Default is 1 second.
# DUMPSLOW_LONG_REQUEST_TIME = 0.5
+# Email admins if the page takes longer than this to render
+# DUMPSLOW_EMAIL_REQUEST_TIME = 10
REDIS_HOST = 'localhost'
REDIS_PORT = 6379

0 comments on commit 2d2c17d

Please sign in to comment.