blob: 58969d194e15975089bce005e025b6651c715fd4 [file] [log] [blame]
stevenvanrossem2fdfbf42016-05-13 15:08:47 +02001"""
peusterm79ef6ae2016-07-08 13:53:57 +02002Copyright (c) 2015 SONATA-NFV
3ALL RIGHTS RESERVED.
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18nor the names of its contributors may be used to endorse or promote
19products derived from this software without specific prior written
20permission.
21
22This work has been performed in the framework of the SONATA project,
23funded by the European Commission under Grant number 671517 through
24the Horizon 2020 and 5G-PPP programmes. The authors would like to
25acknowledge the contributions of their colleagues of the SONATA
26partner consortium (www.sonata-nfv.eu).
stevenvanrossem2fdfbf42016-05-13 15:08:47 +020027"""
28
stevenvanrosseme131bf52016-07-14 11:42:09 +020029
stevenvanrossem1a6843a2016-05-19 12:19:36 +020030import requests
stevenvanrosseme131bf52016-07-14 11:42:09 +020031
stevenvanrossem2fdfbf42016-05-13 15:08:47 +020032
stevenvanrossem48db0512016-05-18 15:43:24 +020033# set this to localhost for now
34# this is correct for son-emu started outside of a container or as a container with net=host
stevenvanrosseme131bf52016-07-14 11:42:09 +020035#TODO if prometheus sdk DB is started outside of emulator, place these globals in an external SDK config file?
36prometheus_ip = 'localhost'
37# when sdk is started with docker-compose, we could use
38# prometheus_ip = 'prometheus'
stevenvanrossem2fdfbf42016-05-13 15:08:47 +020039prometheus_port = '9090'
40prometheus_REST_api = 'http://{0}:{1}'.format(prometheus_ip, prometheus_port)
41
42
43def query_Prometheus(query):
44 url = prometheus_REST_api + '/' + 'api/v1/query?query=' + query
45 # logging.info('query:{0}'.format(url))
stevenvanrossem1a6843a2016-05-19 12:19:36 +020046 req = requests.get(url)
stevenvanrossem1a6843a2016-05-19 12:19:36 +020047 ret = req.json()
stevenvanrossem2fdfbf42016-05-13 15:08:47 +020048 if ret['status'] == 'success':
49 # logging.info('return:{0}'.format(ret))
50 try:
51 ret = ret['data']['result'][0]['value']
52 except:
53 ret = None
54 else:
55 ret = None
56 return ret