More customizable activity period monitoring
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 8 Aug 2010 16:09:30 +0000 (16:09 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 8 Aug 2010 16:09:30 +0000 (16:09 +0000)
bin/djais/views.py
bin/inputs/common.py
html_templates/sources_index.html

index 4d4685363c02271e56d11b89f0c9c34f234a1173..5de86c4d081c43649e092783580cafbc4675fc63 100644 (file)
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+#from __future__ import division
+
 import os
 from datetime import *
 import re
@@ -730,19 +732,20 @@ class StatsSelectorForm(forms.Form):
 
 @http_authenticate(auth, 'ais')
 def sources_index(request):
+    active_minutes = 5
     peers_config = peers_get_config()
     peers_display = []
     for id4, peer in peers_config.iteritems():
         peer['id4'] = id4
         peer['id2'] = id4[2:]
-        peer['active'] = is_id4_active(id4)
+        peer['active'] = is_id4_active(id4, 60*active_minutes)
         peers_display.append(peer)
         
     peers_display = sorted(peers_display, key=lambda k: k['id4'])
 
     form = StatsSelectorForm()
 
-    return render_to_response('sources_index.html', {'sources':peers_display, 'periods': periods, 'form': form}, RequestContext(request))
+    return render_to_response('sources_index.html', {'sources':peers_display, 'active_minutes': active_minutes, 'form': form}, RequestContext(request))
 
 
 @http_authenticate(auth, 'ais')
index 0e56316fd0a6fff8bf1c04055dd60507261f7fd3..2e546d6f0a2d5ee4d1d5670944c86d55ccd33c98 100644 (file)
@@ -89,8 +89,8 @@ def get_source_by_id4(id4):
     '''
     return __all_sources__.get(id4, None) or Source(id4)
 
-def is_id4_active(id4):
-    reference_time =  datetime.utcnow() - timedelta(seconds=60)
+def is_id4_active(id4, seconds):
+    reference_time =  datetime.utcnow() - timedelta(seconds=seconds)
     #logging.error('reference_time=%s', reference_time)
     logfilename = _get_log_filename(id4, reference_time.date())
     #logging.error('logfilename=%s', logfilename)
index 7406c48b9b6635cf2d85da230491caf1bfe0aa87..c2689ace52110a7bd111ab7433f5b39153105a40 100644 (file)
@@ -21,7 +21,7 @@ span.id2 {
 {% endblock %}
 
 {% block content %}
-<h3>Monitored sources</h3>
+<h3>Monitored sources (activity in the last {{ active_minutes }} minute{{ active_minutes|pluralize }})</h3>
 <ul style='padding-left: 1ex;'>
 {% for source in sources %}
 <li style="list-style: none;">