2 Prometheus API helper functions
3 (c) 2016 by Steven Van Rossem <steven.vanrossem@intec.ugent.be>
10 # set this to localhost for now
11 # this is correct for son-emu started outside of a container or as a container with net=host
12 #TODO prometheus sdk DB is started outside of emulator, place these globals in an external SDK config file?
13 prometheus_ip
= '127.0.0.1'
14 prometheus_port
= '9090'
15 prometheus_REST_api
= 'http://{0}:{1}'.format(prometheus_ip
, prometheus_port
)
18 def query_Prometheus(query
):
19 url
= prometheus_REST_api
+ '/' + 'api/v1/query?query=' + query
20 # logging.info('query:{0}'.format(url))
21 #req = urllib2.Request(url)
22 req
= requests
.get(url
)
23 #ret = urllib2.urlopen(req).read()
24 #ret = ast.literal_eval(ret)
26 if ret
['status'] == 'success':
27 # logging.info('return:{0}'.format(ret))
29 ret
= ret
['data']['result'][0]['value']