Merge branch 'master' of git://git.planet-lab.org/plstackapi
diff --git a/planetstack/core/views/stats.py b/planetstack/core/views/stats.py
index 46ebe2e..421fbfe 100644
--- a/planetstack/core/views/stats.py
+++ b/planetstack/core/views/stats.py
@@ -5,7 +5,8 @@
def Stats(request):
model = request.GET['model_name']
pk = int(request.GET['pk'])
- meter = int(request.GET['meter'])
+ meter = request.GET['meter']
+ controller_name = request.GET['controller_name']
- meters = monitor.get_meters(meter, model, pk)
- return json.dumps(meters)
+ meters = driver.get_meter(meter, model, pk)
+ return HttpResponse(json.dumps(meters))
diff --git a/planetstack/monitor/monitordriver.py b/planetstack/monitor/monitordriver.py
index 77e8bfd..50e208c 100644
--- a/planetstack/monitor/monitordriver.py
+++ b/planetstack/monitor/monitordriver.py
@@ -7,6 +7,7 @@
self['average'] = 0
self['sum'] = 0
self['unit'] = 'units'
+ self['stat_list']=[]
# stat_list is a list of dicts
# [ {'timestamp': datetime, 'value': value} ]
diff --git a/planetstack/openstack_observer/ceilometer.py b/planetstack/openstack_observer/ceilometer.py
index 7383524..6875ae8 100644
--- a/planetstack/openstack_observer/ceilometer.py
+++ b/planetstack/openstack_observer/ceilometer.py
@@ -8,9 +8,10 @@
import datetime
import time
from monitor.monitordriver import *
-from core.models import *
+import pdb
def object_to_filter(model_name, pk):
+ from core.models import *
filter_dict = {
'Slice':[Slice, 'tenant_id', 'project_id'],
'Sliver':[Sliver, 'instance_id', 'resource_id'],
@@ -19,7 +20,7 @@
mod,field,tag = filter_dict[model_name]
obj = mod.objects.get(pk=pk)
- return '%s=%s'%(tag,mod[field])
+ return '%s=%s'%(tag,getattr(obj,field))
def cli_to_array(cli_query):
@@ -70,35 +71,37 @@
def meters_to_stats(meters):
stats = DashboardStatistics()
for m in meters:
- timestamp = datetime.datetime.strptime(m.duration_start,'%Y-%m-%dT%H:%M:%S')
- stats.stat_list.append({'timestamp':timestamp, 'value':m.sum})
- stats.sum+=m.sum
- stats.average+=m.sum
- stats.unit = 'ns'
+ timestamp = m.duration_start
+ stats['stat_list'].append({'timestamp':timestamp, 'value':m.sum})
+ stats['sum']+=m.sum
+ stats['average']+=m.sum
+ stats['unit'] = 'ns'
- stats.average/=len(meters)
+ stats['average']/=len(meters)
return stats
-
class CeilometerDriver(MonitorDriver):
def get_meter(self, meter, obj, pk, keystone=None):
- if (not keystone):
- keystone = {}
- keystone['username']=env['OS_USERNAME']
- keystone['password']=env['OS_PASSWORD']
- keystone['auth_url']=env['OS_AUTH_URL']
- keystone['tenant_name']=env['OS_TENANT_NAME']
- keystone['os_cacert']=env['OS_CACERT']
+ keystone = {}
+ keystone['os_username']=env['OS_USERNAME']
+ keystone['os_password']=env['OS_PASSWORD']
+ keystone['os_auth_url']=env['OS_AUTH_URL']
+ keystone['os_tenant_name']=env['OS_TENANT_NAME']
+ keystone['os_cacert']=env['OS_CACERT']
+ keystone['os_region_name']=env['OS_REGION_NAME']
- ceilometer_client = client._get_ksclient(**keystone)
- token = ceilometer_client.auth_token
+ keystone['username']=env['OS_USERNAME']
+ keystone['password']=env['OS_PASSWORD']
+ keystone['auth_url']=env['OS_AUTH_URL']
+ keystone['tenant_name']=env['OS_TENANT_NAME']
+ keystone['cacert']=env['OS_CACERT']
+ keystone['region_name']=env['OS_REGION_NAME']
- ceilo_endpoint = client._get_endpoint(ceilometer_client, **keystone)
- #ceilometer = client.get_client(2, username=keystone['username'], password=keystone['password'], tenant_name=keystone['tenant_name'], auth_url=keystone['auth_url'])
+ keystone['auth_plugin']=client.AuthPlugin(**keystone)
- ceilometer = client.Client('2',endpoint = ceilo_endpoint, token = lambda: token)
-
+ ceilometer = client.get_client(2,**keystone)
+
cur_ts = datetime.datetime.fromtimestamp(time.time()-86400)
str_ts = cur_ts.strftime('%Y-%m-%dT%H:%M:%S')