fix up for internal use

This commit is contained in:
Sandy Walsh 2012-02-27 18:46:20 -06:00
parent ecfc3abae8
commit 5fd222e165
6 changed files with 50 additions and 55 deletions

View File

@ -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<tenant_id>\d+)/$', 'dss.stackmon.views.home', name='home'),
url(r'^(?P<tenant_id>\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<tenant_id>\d+)/$', 'stacktach.views.home', name='home'),
url(r'^(?P<tenant_id>\d+)/data/$', 'stacktach.views.data',
name='data'),
url(r'^(?P<tenant_id>\d+)/details/(?P<column>\w+)/(?P<row_id>\d+)/$',
'dss.stackmon.views.details', name='details'),
'stacktach.views.details', name='details'),
url(r'^(?P<tenant_id>\d+)/expand/(?P<row_id>\d+)/$',
'dss.stackmon.views.expand', name='expand'),
'stacktach.views.expand', name='expand'),
url(r'^(?P<tenant_id>\d+)/host_status/$',
'dss.stackmon.views.host_status', name='host_status'),
'stacktach.views.host_status', name='host_status'),
url(r'^(?P<tenant_id>\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'),
)

View File

@ -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)

View File

@ -21,7 +21,8 @@ under the License.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.timers.js"></script>
<script type="text/javascript" src="/static/jquery.timers.js"></script>
<link href='http://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=PT+Sans&subset=latin' rel='stylesheet' type='text/css'>

View File

@ -15,9 +15,9 @@
<ul>
<li>Get a <a href='/new_tenant'>StackTach Tenant ID</a>
<li>Add <pre>--notification_driver=nova.notifier.rabbit_notifier</pre> and
<li><pre>--notification_topics=monitor</pre> to your nova.conf file.
<li>Configure and run the <a target='_blank' href='https://github.com/SandyWalsh/StackTach'>StackTach Worker</a> somewhere in your Nova development environment.
<li>Restart Nova and visit http://darksecretsoftware.com/stacktach/[your_tenant_id]/ to see your Nova installation in action!
<li><pre>--notification_topics=info,monitor</pre> to your nova.conf file.
<li>Configure and run the <a target='_blank' href='https://github.com/Rackspace/StackTach'>StackTach Worker</a> somewhere in your Nova development environment.
<li>Restart Nova and visit http://[your server]/[your_tenant_id]/ to see your Nova installation in action!
</ul>
</div>
</div>

View File

@ -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')),
)

View File

@ -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")