Skip to content
Snippets Groups Projects
Commit 50b86035 authored by ptangu01's avatar ptangu01
Browse files

add statistics

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@1052 b32b6428-25c9-4566-ad07-03861ab6144f
parent a1d33c9f
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,7 @@ def run(filename='xaalrestapi',confDir=xAAL.config.CONF_DIR):
apidevices = cherrypyrestapi.Devices(dbname)
apisender = cherrypyrestapi.Sender(eng,dev)
apinotifications = cherrypyrestapi.Notifications(dev)
apistatistics = cherrypyrestapi.Statistics(dbname)
# To configure server and engine
cherrypy.config.update({'environment': 'production',
......@@ -116,6 +117,7 @@ def run(filename='xaalrestapi',confDir=xAAL.config.CONF_DIR):
cherrypy.tree.mount(apidevices,'/api/xaal/devices',config=conf)
cherrypy.tree.mount(apisender,'/api/xaal/send',config=conf)
cherrypy.tree.mount(apinotifications,'/api/xaal/notifications',config=conf)
cherrypy.tree.mount(apistatistics,'/api/xaal/statistics',config=conf)
cherrypy.engine.start()
cherrypy.engine.block()
......
......@@ -124,3 +124,28 @@ class Notifications(object):
yield "event: attributesChange\n" + "data: " + str(data) + "\n\n"
return stream()
GET._cp_config = {'response.stream': True}
class Statistics(object):
"""
Expose statistics related to the xAAL bus. i.e. number of devices, etc.
"""
exposed = True
def __init__(self,dbname):
self._dbname = dbname
def GET(self):
db=shelve.open(self._dbname)
devices=db['devices']
db.close()
cherrypy.response.headers['Content-Type'] = "application/json"
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
result={}
result['devices']=len(devices)
return ujson.dumps(result)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment