def admin_stats(admin_site, request, **kwargs): boxes = [] memory_heap = get_memory_heap() if memory_heap: boxes.append({'title':'Memory Heap', 'body':'<pre>%s</pre>' % memory_heap}) process_info = get_process_info() if process_info: body = '<ul>%s</ul>' % ''.join(['<li>%s: %s</li>'%(k,v) for k,v in process_info]) boxes.append({'title':'Process Info', 'body':body}) return boxes
def process_exception(self, request, response, exception): logger = get_logger('london') full_url = 'http%s://%s%s'%('s' if request.is_secure() else '', request.META['HTTP_HOST'], request.get_full_path()) exception.name = exception.__class__.__name__ # Traceback tb = traceback.format_exc() # Heap heap = get_memory_heap() # ps info process_info = get_process_info() if app_settings.PRINT_TRACEBACK: msg = [] msg.append('-'*40) msg.append(tb) msg.append('-'*40) if heap: msg.append(heap) msg.append('-'*40) if process_info: msg.append(['%s: %s'%(k,v) for k,v in process_info]) msg.append('-'*40) logger.error('\n'.join(msg)) # URL not found if isinstance(exception, Http404): if app_settings.PAGE_NOT_FOUND_NOTIFICATION: body = [ 'URL: %s'%full_url, 'Headers:', ] for k,v in request.META.items(): body.append('- %s: %s'%(k,v)) if request.POST: body.append('POST Data:') for k,v in request.POST.items(): body.append('- %s: %s'%(k,v)) send_message_to_admins(subject='Page not found in the site', body='\n'.join(body)) else: # Error notification if not app_settings.DEBUG and app_settings.SERVER_ERROR_NOTIFICATION: body = [ '%s: %s'%(exception.__class__.__name__, exception), 'URL: %s'%full_url, '\nHeaders:', ] for k,v in request.META.items(): body.append('- %s: %s'%(k,v)) if request.POST: body.append('\nPOST Data:') for k,v in request.POST.items(): body.append(u'- %s: %s' % (k,unicode(v))) body.append('\nTraceback:') body.append(tb) if heap: body.append('\nMemory Heap:') body.append(heap) if process_info: body.append('\nProcess Info:') for k,v in process_info: body.append('\n- %s: %s' % (k,v)) send_message_to_admins(subject='Error in the server', body='\n'.join(body)) # Response if isinstance(exception, Http404): view = import_anything(app_settings.ERROR_HANDLERS['404']) else: view = import_anything(app_settings.ERROR_HANDLERS['500']) resp = view(request, exception=exception, traceback_string=tb, heap_string=heap, process_info=process_info) if isinstance(exception, Http404): return HttpResponseNotFound(resp.content) else: return HttpResponseServerError(resp.content)