diff --git a/stacktach/models.py b/stacktach/models.py index 0e403a7..0959809 100644 --- a/stacktach/models.py +++ b/stacktach/models.py @@ -20,6 +20,8 @@ from django.db import models class Tenant(models.Model): email = models.CharField(max_length=50) project_name = models.CharField(max_length=50) + nova_stats_template = models.CharField(max_length=200) + loggly_template = models.CharField(max_length=200) tenant_id = models.AutoField(primary_key=True, unique=True) @@ -35,13 +37,13 @@ class RawData(models.Model): blank=True, db_index=True) when = models.DateTimeField(db_index=True) microseconds = models.IntegerField(default=0) - publisher = models.CharField(max_length=50, null=True, + publisher = models.CharField(max_length=100, null=True, blank=True, db_index=True) event = models.CharField(max_length=50, null=True, blank=True, db_index=True) service = models.CharField(max_length=50, null=True, blank=True, db_index=True) - host = models.CharField(max_length=50, null=True, + host = models.CharField(max_length=100, null=True, blank=True, db_index=True) instance = models.CharField(max_length=50, null=True, blank=True, db_index=True) @@ -50,4 +52,4 @@ class RawData(models.Model): class TenantForm(forms.ModelForm): class Meta: model = Tenant - fields = ('email', 'project_name') + fields = ('email', 'project_name', 'nova_stats_template', 'loggly_template') diff --git a/stacktach/views.py b/stacktach/views.py index 03ff951..95907cc 100644 --- a/stacktach/views.py +++ b/stacktach/views.py @@ -83,13 +83,22 @@ def _parse(tenant, args, json_args): return {} -def _post_process_raw_data(rows, highlight=None): +def _post_process_raw_data(rows, state, highlight=None): for row in rows: if "error" in row.routing_key: row.is_error = True if highlight and row.id == int(highlight): row.highlight = True row.when += datetime.timedelta(microseconds=row.microseconds) + novastats = state.tenant.nova_stats_template + if novastats and row.instance: + novastats = novastats.replace("[instance]", row.instance) + row.novastats = novastats + loggly = state.tenant.loggly_template + if loggly and row.instance: + loggly = loggly.replace("[instance]", row.instance) + row.loggly = loggly + class State(object): def __init__(self): @@ -203,12 +212,13 @@ def details(request, tenant_id, column, row_id): if column != 'when': rows = rows.filter(**{column:value}) else: + value += datetime.timedelta(microseconds=row.microseconds) from_time = value - datetime.timedelta(minutes=1) to_time = value + datetime.timedelta(minutes=1) rows = rows.filter(when__range=(from_time, to_time)) rows = rows.order_by('-when', '-microseconds')[:200] - _post_process_raw_data(rows, highlight=row_id) + _post_process_raw_data(rows, state, highlight=row_id) c['rows'] = rows c['allow_expansion'] = True c['show_absolute_time'] = True @@ -231,21 +241,25 @@ def host_status(request, tenant_id): state = _get_state(request, tenant_id) c = _default_context(state) hosts = models.RawData.objects.filter(tenant=tenant_id).\ - filter(host__gt='').\ order_by('-when', '-microseconds')[:20] - _post_process_raw_data(hosts) + _post_process_raw_data(hosts, state) c['rows'] = hosts return render_to_response('host_status.html', c) @tenant_check -def instance_status(request, tenant_id): +def search(request, tenant_id): state = _get_state(request, tenant_id) c = _default_context(state) - instances = models.RawData.objects.filter(tenant=tenant_id).\ - exclude(instance='n/a').\ - exclude(instance__isnull=True).\ - order_by('-when', '-microseconds')[:20] - _post_process_raw_data(instances) - c['rows'] = instances - return render_to_response('instance_status.html', c) + column = request.POST.get('field', None) + value = request.POST.get('value', None) + rows = None + if column != None and value != None: + rows = models.RawData.objects.filter(tenant=tenant_id).\ + filter(**{column:value}).\ + order_by('-when', '-microseconds')[:200] + _post_process_raw_data(rows, state) + c['rows'] = rows + c['allow_expansion'] = True + c['show_absolute_time'] = True + return render_to_response('rows.html', c) diff --git a/templates/index.html b/templates/index.html index 497f375..2a9a54c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -28,8 +28,8 @@ {% endblock %} {% block body %} -