Add API entry for Statistics
This patch adds a new method in API to get API statistics information. Change-Id: I7a0b0f6a9e306653ed5d231a5bfaae79f9ff8d27 Partly-Implements: blueprint api-request-stats
This commit is contained in:
parent
4030ecee24
commit
95a31b2394
@ -15,7 +15,9 @@
|
||||
import time
|
||||
|
||||
from muranoapi.api import v1
|
||||
from muranoapi.db.services import stats
|
||||
from muranoapi.openstack.common import log as logging
|
||||
from muranoapi.openstack.common import wsgi
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -86,3 +88,17 @@ def update_error_count(api, method, ex_time, tenant=None):
|
||||
def init_stats():
|
||||
if not v1.stats:
|
||||
v1.stats = RequestStatisticsCollection()
|
||||
|
||||
|
||||
class Controller(object):
|
||||
def get(self, request):
|
||||
model = stats.Statistics()
|
||||
entries = model.get_all()
|
||||
ent_list = []
|
||||
for entry in entries:
|
||||
ent_list.append(entry.to_dict())
|
||||
return ent_list
|
||||
|
||||
|
||||
def create_resource():
|
||||
return wsgi.Resource(Controller())
|
||||
|
@ -17,6 +17,7 @@ from muranoapi.api.v1 import catalog
|
||||
from muranoapi.api.v1 import deployments
|
||||
from muranoapi.api.v1 import environment_statistics
|
||||
from muranoapi.api.v1 import environments
|
||||
from muranoapi.api.v1 import request_statistics
|
||||
from muranoapi.api.v1 import services
|
||||
from muranoapi.api.v1 import sessions
|
||||
from muranoapi.openstack.common import wsgi
|
||||
@ -171,4 +172,10 @@ class API(wsgi.Router):
|
||||
action='download',
|
||||
conditions={'method': ['GET']})
|
||||
|
||||
req_stats_resource = request_statistics.create_resource()
|
||||
mapper.connect('/stats',
|
||||
controller=req_stats_resource,
|
||||
action='get',
|
||||
conditions={'method': ['GET']})
|
||||
|
||||
super(API, self).__init__(mapper)
|
||||
|
@ -18,6 +18,13 @@ from muranoapi.db import session as db_session
|
||||
|
||||
|
||||
class Statistics(object):
|
||||
|
||||
@staticmethod
|
||||
def get_all():
|
||||
db = db_session.get_session()
|
||||
stats = db.query(m.ApiStats).all()
|
||||
return stats
|
||||
|
||||
@staticmethod
|
||||
def get_stats_by_id(stats_id):
|
||||
db = db_session.get_session()
|
||||
|
Loading…
Reference in New Issue
Block a user