diff --git a/stacktach/models.py b/stacktach/models.py index f09e3ff..9fde6b2 100644 --- a/stacktach/models.py +++ b/stacktach/models.py @@ -38,7 +38,8 @@ class RawData(models.Model): blank=True, db_index=True) old_task = models.CharField(max_length=30, null=True, blank=True, db_index=True) - when = models.DecimalField(max_digits=20, decimal_places=6) + when = models.DecimalField(max_digits=20, decimal_places=6, + db_index=True) publisher = models.CharField(max_length=100, null=True, blank=True, db_index=True) event = models.CharField(max_length=50, null=True, @@ -81,10 +82,12 @@ class Timing(models.Model): start_raw = models.ForeignKey(RawData, related_name='+', null=True) end_raw = models.ForeignKey(RawData, related_name='+', null=True) - start_when = models.DecimalField(null=True, max_digits=20, decimal_places=6) + start_when = models.DecimalField(null=True, max_digits=20, + decimal_places=6) end_when = models.DecimalField(null=True, max_digits=20, decimal_places=6) - diff = models.DecimalField(null=True, max_digits=20, decimal_places=6) + diff = models.DecimalField(null=True, max_digits=20, decimal_places=6, + db_index=True) class RequestTracker(models.Model): @@ -93,9 +96,10 @@ class RequestTracker(models.Model): final .end event (with the same Request ID).""" request_id = models.CharField(max_length=50, db_index=True) lifecycle = models.ForeignKey(Lifecycle) - last_timing = models.ForeignKey(Timing, null=true) - start = models.DecimalField(max_digits=20, decimal_places=6) - duration = models.DecimalField(max_digits=20, decimal_places=6) + last_timing = models.ForeignKey(Timing, null=True, db_index=True) + start = models.DecimalField(max_digits=20, decimal_places=6, db_index=True) + duration = models.DecimalField(max_digits=20, decimal_places=6, + db_index=True) # Not used ... but soon hopefully. - completed = models.BooleanField(default=False) + completed = models.BooleanField(default=False, db_index=True) diff --git a/stacktach/stacky_server.py b/stacktach/stacky_server.py index 127d400..327bb25 100644 --- a/stacktach/stacky_server.py +++ b/stacktach/stacky_server.py @@ -67,7 +67,7 @@ def sec_to_time(diff): seconds -= (hours * SECS_PER_HOUR) minutes = seconds / 60 seconds -= (minutes * 60) - usec = ('%.2f' % usec).lstrip('0') + usec = str(usec)[1:4] return "%dd %02d:%02d:%02d%s" % (days, hours, minutes, seconds, usec) @@ -279,8 +279,9 @@ def do_watch(request, deployment_id): return rsp([c, results, str(dec_now)]) -def do_kpi(request): +def do_kpi(request, tenant_id=None): yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1) + yesterday = dt.dt_to_decimal(yesterday) trackers = models.RequestTracker.objects.select_related() \ .exclude(last_timing=None) \ .exclude(start__lt=yesterday) \ @@ -292,6 +293,7 @@ def do_kpi(request): end_event = track.last_timing.end_raw event = end_event.event[:-len(".end")] uuid = track.lifecycle.instance - results.append([event, sec_to_time(track.duration), + if tenant_id == None or (tenant_id == end_event.tenant): + results.append([event, sec_to_time(track.duration), uuid, end_event.deployment.name]) return rsp(results) diff --git a/stacktach/urls.py b/stacktach/urls.py index 867b9ae..212cdea 100644 --- a/stacktach/urls.py +++ b/stacktach/urls.py @@ -17,6 +17,7 @@ urlpatterns = patterns('', url(r'stacky/watch/(?P\d+)/$', 'stacktach.stacky_server.do_watch'), url(r'stacky/kpi/$', 'stacktach.stacky_server.do_kpi'), + url(r'stacky/kpi/(?P\d+)/$', 'stacktach.stacky_server.do_kpi'), url(r'^(?P\d+)/$', 'stacktach.views.home', name='home'), url(r'^(?P\d+)/details/(?P\w+)/(?P\d+)/$', diff --git a/stacktach/views.py b/stacktach/views.py index 042ae0b..c01a922 100644 --- a/stacktach/views.py +++ b/stacktach/views.py @@ -87,7 +87,7 @@ def start_kpi_tracking(lifecycle, raw): start=raw.when, lifecycle=lifecycle, last_timing=None, - duration=0.0) + duration=str(0.0)) tracker.save() @@ -102,7 +102,8 @@ def update_kpi(lifecycle, timing, raw): Until then, we'll take the lazy route and be aware of these potential fence-post issues.""" - trackers = models.RequestTracker.objects.filter(request_id=raw.request.id) + trackers = models.RequestTracker.objects.\ + filter(request_id=raw.request_id) if len(trackers) == 0: return @@ -146,7 +147,7 @@ def aggregate(raw): if not step in ['start', 'end']: # Perhaps it's an operation initiated in the API? - start_kpi_tracking(lifecyle, raw) + start_kpi_tracking(lifecycle, raw) return # We are going to try to track every event pair that comes @@ -313,7 +314,9 @@ def latest_raw(request, deployment_id): """This is the 2sec ticker that updates the Recent Activity box.""" deployment_id = int(deployment_id) c = _default_context(request, deployment_id) - query = models.RawData.objects.select_related() + then = datetime.datetime.utcnow() - datetime.timedelta(hours=1) + thend = dt.dt_to_decimal(then) + query = models.RawData.objects.select_related().filter(when__gt=thend) if deployment_id > 0: query = query.filter(deployment=deployment_id) rows = query.order_by('-when')[:20] diff --git a/worker/stacktach.sh b/worker/stacktach.sh index ccc87c8..16794fa 100755 --- a/worker/stacktach.sh +++ b/worker/stacktach.sh @@ -1,6 +1,6 @@ #!/bin/bash -WORKDIR=/srv/www/stacktach/django/stproject/ +WORKDIR=/srv/www/stacktach/app DAEMON=/usr/bin/python ARGS=$WORKDIR/worker/start_workers.py PIDFILE=/var/run/stacktach.pid