2 Prometheus API helper functions
3 (c) 2016 by Steven Van Rossem <steven.vanrossem@intec.ugent.be>
9 # set this to localhost for now
10 # this is correct for son-emu started outside of a container or as a container with net=host
11 prometheus_ip
= '127.0.0.1'
12 prometheus_port
= '9090'
13 prometheus_REST_api
= 'http://{0}:{1}'.format(prometheus_ip
, prometheus_port
)
16 def query_Prometheus(query
):
17 url
= prometheus_REST_api
+ '/' + 'api/v1/query?query=' + query
18 # logging.info('query:{0}'.format(url))
19 req
= urllib2
.Request(url
)
20 ret
= urllib2
.urlopen(req
).read()
21 ret
= ast
.literal_eval(ret
)
22 if ret
['status'] == 'success':
23 # logging.info('return:{0}'.format(ret))
25 ret
= ret
['data']['result'][0]['value']