Skip to content

Commit

Permalink
Add a metric web api.
Browse files Browse the repository at this point in the history
  • Loading branch information
ateska committed Nov 6, 2018
1 parent be0cc13 commit bf536ca
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bspump/web/__init__.py
Expand Up @@ -56,6 +56,25 @@ async def lookup(request):
content_type="application/octet-stream")


async def metric_list(request):
app = request.app['app']
svc = app.get_service("asab.MetricsService")
return asab.web.rest.json_response(request, svc.Metrics)


async def metric_detail(request):
metric_id = request.match_info.get('metric_id')
app = request.app['app']
svc = app.get_service("asab.MetricsService")

print(">>>", metric_id)
metric = svc.Metrics.get(metric_id)
if metric is None:
raise aiohttp.web.HTTPNotFound()

return asab.web.rest.json_response(request, metric)


def initialize_web(app, listen):
app.add_module(asab.web.Module)

Expand All @@ -78,4 +97,7 @@ def initialize_web(app, listen):

container.WebApp.router.add_get('/lookup/{lookup_id}', lookup)

container.WebApp.router.add_get('/metric', metric_list)
container.WebApp.router.add_get('/metric/{metric_id}', metric_detail)

return websvc

0 comments on commit bf536ca

Please sign in to comment.