From 5fd222e165599cd30ce84204ff356c2f9273c0c5 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Mon, 27 Feb 2012 18:46:20 -0600 Subject: [PATCH] fix up for internal use --- stacktach/urls.py | 28 +++++++++------------------- stacktach/views.py | 36 +++++++++++++++++++----------------- templates/base.html | 3 ++- templates/welcome.html | 6 +++--- urls.py | 8 +------- worker.py | 24 ++++++++++++++++-------- 6 files changed, 50 insertions(+), 55 deletions(-) diff --git a/stacktach/urls.py b/stacktach/urls.py index 2360446..03595eb 100644 --- a/stacktach/urls.py +++ b/stacktach/urls.py @@ -1,28 +1,18 @@ from django.conf.urls.defaults import patterns, include, url -# Uncomment the next two lines to enable the admin: -# from django.contrib import admin -# admin.autodiscover() - urlpatterns = patterns('', - url(r'^$', 'dss.stackmon.views.welcome', name='welcome'), - url(r'new_tenant', 'dss.stackmon.views.new_tenant', name='new_tenant'), - url(r'logout', 'dss.stackmon.views.logout', name='logout'), - url(r'^(?P\d+)/$', 'dss.stackmon.views.home', name='home'), - url(r'^(?P\d+)/data/$', 'dss.stackmon.views.data', + url(r'^$', 'stacktach.views.welcome', name='welcome'), + url(r'new_tenant', 'stacktach.views.new_tenant', name='new_tenant'), + url(r'logout', 'stacktach.views.logout', name='logout'), + url(r'^(?P\d+)/$', 'stacktach.views.home', name='home'), + url(r'^(?P\d+)/data/$', 'stacktach.views.data', name='data'), url(r'^(?P\d+)/details/(?P\w+)/(?P\d+)/$', - 'dss.stackmon.views.details', name='details'), + 'stacktach.views.details', name='details'), url(r'^(?P\d+)/expand/(?P\d+)/$', - 'dss.stackmon.views.expand', name='expand'), + 'stacktach.views.expand', name='expand'), url(r'^(?P\d+)/host_status/$', - 'dss.stackmon.views.host_status', name='host_status'), + 'stacktach.views.host_status', name='host_status'), url(r'^(?P\d+)/instance_status/$', - 'dss.stackmon.views.instance_status', name='instance_status'), - - # Uncomment the admin/doc line below to enable admin documentation: - # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: - # url(r'^admin/', include(admin.site.urls)), + 'stacktach.views.instance_status', name='instance_status'), ) diff --git a/stacktach/views.py b/stacktach/views.py index 36ff13d..03ff951 100644 --- a/stacktach/views.py +++ b/stacktach/views.py @@ -4,8 +4,9 @@ from django.shortcuts import render_to_response from django import http from django import template from django.utils.functional import wraps +from django.views.decorators.csrf import csrf_protect -from dss.stackmon import models +from stacktach import models import datetime import json @@ -148,22 +149,22 @@ def _default_context(state): def welcome(request): - state = _reset_state(request, None) - return render_to_response('stackmon/welcome.html', _default_context(state)) + state = _reset_state(request) + return render_to_response('welcome.html', _default_context(state)) @tenant_check def home(request, tenant_id): state = _get_state(request, tenant_id) - return render_to_response('stackmon/index.html', _default_context(state)) + return render_to_response('index.html', _default_context(state)) def logout(request): del request.session['state'] - return render_to_response('stackmon/welcome.html', _default_context(None)) + return render_to_response('welcome.html', _default_context(None)) -@tenant_check +@csrf_protect def new_tenant(request): state = _get_state(request) context = _default_context(state) @@ -172,12 +173,13 @@ def new_tenant(request): if form.is_valid(): rec = models.Tenant(**form.cleaned_data) rec.save() - _reset_state(request, rec.tenant_id) - return http.HttpResponseRedirect('/stacktach/%d' % rec.tenant_id) + _reset_state(request) + return http.HttpResponseRedirect('/%d' % rec.tenant_id) else: form = models.TenantForm() context['form'] = form - return render_to_response('stackmon/new_tenant.html', context) + return render_to_response('new_tenant.html', context, + context_instance=template.RequestContext(request)) @tenant_check @@ -188,7 +190,7 @@ def data(request, tenant_id): c = _default_context(state) fields = _parse(state.tenant, args, raw_args) c['cooked_args'] = fields - return render_to_response('stackmon/data.html', c) + return render_to_response('data.html', c) @tenant_check @@ -197,7 +199,7 @@ def details(request, tenant_id, column, row_id): c = _default_context(state) row = models.RawData.objects.get(pk=row_id) value = getattr(row, column) - rows = models.RawData.objects.filter(tenant_id=tenant_id) + rows = models.RawData.objects.filter(tenant=tenant_id) if column != 'when': rows = rows.filter(**{column:value}) else: @@ -210,7 +212,7 @@ def details(request, tenant_id, column, row_id): c['rows'] = rows c['allow_expansion'] = True c['show_absolute_time'] = True - return render_to_response('stackmon/rows.html', c) + return render_to_response('rows.html', c) @tenant_check @@ -221,29 +223,29 @@ def expand(request, tenant_id, row_id): payload = json.loads(row.json) pp = pprint.PrettyPrinter() c['payload'] = pp.pformat(payload) - return render_to_response('stackmon/expand.html', c) + return render_to_response('expand.html', c) @tenant_check def host_status(request, tenant_id): state = _get_state(request, tenant_id) c = _default_context(state) - hosts = models.RawData.objects.filter(tenant_id=tenant_id).\ + hosts = models.RawData.objects.filter(tenant=tenant_id).\ filter(host__gt='').\ order_by('-when', '-microseconds')[:20] _post_process_raw_data(hosts) c['rows'] = hosts - return render_to_response('stackmon/host_status.html', c) + return render_to_response('host_status.html', c) @tenant_check def instance_status(request, tenant_id): state = _get_state(request, tenant_id) c = _default_context(state) - instances = models.RawData.objects.filter(tenant_id=tenant_id).\ + 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('stackmon/instance_status.html', c) + return render_to_response('instance_status.html', c) diff --git a/templates/base.html b/templates/base.html index 49495d5..f39ea88 100644 --- a/templates/base.html +++ b/templates/base.html @@ -21,7 +21,8 @@ under the License. - + + diff --git a/templates/welcome.html b/templates/welcome.html index bcaa144..c86a069 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -15,9 +15,9 @@
  • Get a StackTach Tenant ID
  • Add
    --notification_driver=nova.notifier.rabbit_notifier
    and -
  • --notification_topics=monitor
    to your nova.conf file. -
  • Configure and run the StackTach Worker somewhere in your Nova development environment. -
  • Restart Nova and visit http://darksecretsoftware.com/stacktach/[your_tenant_id]/ to see your Nova installation in action! +
  • --notification_topics=info,monitor
    to your nova.conf file. +
  • Configure and run the StackTach Worker somewhere in your Nova development environment. +
  • Restart Nova and visit http://[your server]/[your_tenant_id]/ to see your Nova installation in action!
diff --git a/urls.py b/urls.py index c236830..5ae73fa 100644 --- a/urls.py +++ b/urls.py @@ -5,11 +5,5 @@ from django.conf.urls.defaults import patterns, include, url # admin.autodiscover() urlpatterns = patterns('', - url(r'^', include('stacktach.urls')), - - # Uncomment the admin/doc line below to enable admin documentation: - # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: - # url(r'^admin/', include(admin.site.urls)), + url(r'^', include('stacktach.url')), ) diff --git a/worker.py b/worker.py index 85da605..d45572e 100644 --- a/worker.py +++ b/worker.py @@ -28,6 +28,16 @@ import urllib2 # CHANGE THESE FOR YOUR INSTALLATION ... TENANT_ID = 1 URL = 'http://darksecretsoftware.com/stacktach/%d/data/' % TENANT_ID +RABBIT_HOST = "localhost" +RABBIT_PORT = 5672 +RABBIT_USERID = "guest" +RABBIT_PASSWORD = "guest" +RABBIT_VIRTUAL_HOST = "/" + +try: + from worker_conf import * +except ImportError: + pass # For now we'll just grab all the fanout messages from compute to scheduler ... scheduler_exchange = kombu.entity.Exchange("scheduler_fanout", type="fanout", @@ -43,7 +53,7 @@ scheduler_queues = [ ] nova_exchange = kombu.entity.Exchange("nova", type="topic", - durable=False, auto_delete=False, + durable=True, auto_delete=False, exclusive=False) nova_queues = [ @@ -51,12 +61,6 @@ nova_queues = [ exclusive=False, routing_key='monitor.*'), ] -RABBIT_HOST = "localhost" -RABBIT_PORT = 5672 -RABBIT_USERID = "guest" -RABBIT_PASSWORD = "guest" -RABBIT_VIRTUAL_HOST = "/" - class SchedulerFanoutConsumer(kombu.mixins.ConsumerMixin): def __init__(self, connection): @@ -89,7 +93,7 @@ class SchedulerFanoutConsumer(kombu.mixins.ConsumerMixin): def on_scheduler(self, body, message): # Uncomment if you want periodic compute node status updates. - # self._process(body, message) + #self._process(body, message) message.ack() def on_nova(self, body, message): @@ -98,6 +102,9 @@ class SchedulerFanoutConsumer(kombu.mixins.ConsumerMixin): if __name__ == "__main__": + print "StackTach", URL + print "Rabbit", RABBIT_HOST, RABBIT_PORT, RABBIT_USERID, RABBIT_VIRTUAL_HOST + params = dict(hostname=RABBIT_HOST, port=RABBIT_PORT, userid=RABBIT_USERID, @@ -107,6 +114,7 @@ if __name__ == "__main__": with kombu.connection.BrokerConnection(**params) as conn: consumer = SchedulerFanoutConsumer(conn) try: + print "Listening" consumer.run() except KeyboardInterrupt: print("bye bye")