Merge branch 'master' of git://github.com/rackspace/stacktach

This commit is contained in:
root 2012-12-12 16:08:41 -06:00
commit 6ba0458fbb
5 changed files with 25 additions and 15 deletions

View File

@ -38,7 +38,8 @@ class RawData(models.Model):
blank=True, db_index=True) blank=True, db_index=True)
old_task = models.CharField(max_length=30, null=True, old_task = models.CharField(max_length=30, null=True,
blank=True, db_index=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, publisher = models.CharField(max_length=100, null=True,
blank=True, db_index=True) blank=True, db_index=True)
event = models.CharField(max_length=50, null=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) start_raw = models.ForeignKey(RawData, related_name='+', null=True)
end_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) 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): class RequestTracker(models.Model):
@ -93,9 +96,10 @@ class RequestTracker(models.Model):
final .end event (with the same Request ID).""" final .end event (with the same Request ID)."""
request_id = models.CharField(max_length=50, db_index=True) request_id = models.CharField(max_length=50, db_index=True)
lifecycle = models.ForeignKey(Lifecycle) lifecycle = models.ForeignKey(Lifecycle)
last_timing = models.ForeignKey(Timing, null=true) last_timing = models.ForeignKey(Timing, null=True, db_index=True)
start = models.DecimalField(max_digits=20, decimal_places=6) start = models.DecimalField(max_digits=20, decimal_places=6, db_index=True)
duration = models.DecimalField(max_digits=20, decimal_places=6) duration = models.DecimalField(max_digits=20, decimal_places=6,
db_index=True)
# Not used ... but soon hopefully. # Not used ... but soon hopefully.
completed = models.BooleanField(default=False) completed = models.BooleanField(default=False, db_index=True)

View File

@ -67,7 +67,7 @@ def sec_to_time(diff):
seconds -= (hours * SECS_PER_HOUR) seconds -= (hours * SECS_PER_HOUR)
minutes = seconds / 60 minutes = seconds / 60
seconds -= (minutes * 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) 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)]) 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 = datetime.datetime.utcnow() - datetime.timedelta(days=1)
yesterday = dt.dt_to_decimal(yesterday)
trackers = models.RequestTracker.objects.select_related() \ trackers = models.RequestTracker.objects.select_related() \
.exclude(last_timing=None) \ .exclude(last_timing=None) \
.exclude(start__lt=yesterday) \ .exclude(start__lt=yesterday) \
@ -292,6 +293,7 @@ def do_kpi(request):
end_event = track.last_timing.end_raw end_event = track.last_timing.end_raw
event = end_event.event[:-len(".end")] event = end_event.event[:-len(".end")]
uuid = track.lifecycle.instance uuid = track.lifecycle.instance
if tenant_id == None or (tenant_id == end_event.tenant):
results.append([event, sec_to_time(track.duration), results.append([event, sec_to_time(track.duration),
uuid, end_event.deployment.name]) uuid, end_event.deployment.name])
return rsp(results) return rsp(results)

View File

@ -17,6 +17,7 @@ urlpatterns = patterns('',
url(r'stacky/watch/(?P<deployment_id>\d+)/$', url(r'stacky/watch/(?P<deployment_id>\d+)/$',
'stacktach.stacky_server.do_watch'), 'stacktach.stacky_server.do_watch'),
url(r'stacky/kpi/$', 'stacktach.stacky_server.do_kpi'), url(r'stacky/kpi/$', 'stacktach.stacky_server.do_kpi'),
url(r'stacky/kpi/(?P<tenant_id>\d+)/$', 'stacktach.stacky_server.do_kpi'),
url(r'^(?P<deployment_id>\d+)/$', 'stacktach.views.home', name='home'), url(r'^(?P<deployment_id>\d+)/$', 'stacktach.views.home', name='home'),
url(r'^(?P<deployment_id>\d+)/details/(?P<column>\w+)/(?P<row_id>\d+)/$', url(r'^(?P<deployment_id>\d+)/details/(?P<column>\w+)/(?P<row_id>\d+)/$',

View File

@ -87,7 +87,7 @@ def start_kpi_tracking(lifecycle, raw):
start=raw.when, start=raw.when,
lifecycle=lifecycle, lifecycle=lifecycle,
last_timing=None, last_timing=None,
duration=0.0) duration=str(0.0))
tracker.save() 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 Until then, we'll take the lazy route and be aware of these
potential fence-post issues.""" 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: if len(trackers) == 0:
return return
@ -146,7 +147,7 @@ def aggregate(raw):
if not step in ['start', 'end']: if not step in ['start', 'end']:
# Perhaps it's an operation initiated in the API? # Perhaps it's an operation initiated in the API?
start_kpi_tracking(lifecyle, raw) start_kpi_tracking(lifecycle, raw)
return return
# We are going to try to track every event pair that comes # 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.""" """This is the 2sec ticker that updates the Recent Activity box."""
deployment_id = int(deployment_id) deployment_id = int(deployment_id)
c = _default_context(request, 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: if deployment_id > 0:
query = query.filter(deployment=deployment_id) query = query.filter(deployment=deployment_id)
rows = query.order_by('-when')[:20] rows = query.order_by('-when')[:20]

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
WORKDIR=/srv/www/stacktach/django/stproject/ WORKDIR=/srv/www/stacktach/app
DAEMON=/usr/bin/python DAEMON=/usr/bin/python
ARGS=$WORKDIR/worker/start_workers.py ARGS=$WORKDIR/worker/start_workers.py
PIDFILE=/var/run/stacktach.pid PIDFILE=/var/run/stacktach.pid