| stevenvanrossem | 2fdfbf4 | 2016-05-13 15:08:47 +0200 | [diff] [blame] | 1 | """ |
| peusterm | 79ef6ae | 2016-07-08 13:53:57 +0200 | [diff] [blame] | 2 | Copyright (c) 2015 SONATA-NFV |
| 3 | ALL RIGHTS RESERVED. |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | |
| 17 | Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] |
| 18 | nor the names of its contributors may be used to endorse or promote |
| 19 | products derived from this software without specific prior written |
| 20 | permission. |
| 21 | |
| 22 | This work has been performed in the framework of the SONATA project, |
| 23 | funded by the European Commission under Grant number 671517 through |
| 24 | the Horizon 2020 and 5G-PPP programmes. The authors would like to |
| 25 | acknowledge the contributions of their colleagues of the SONATA |
| 26 | partner consortium (www.sonata-nfv.eu). |
| stevenvanrossem | 2fdfbf4 | 2016-05-13 15:08:47 +0200 | [diff] [blame] | 27 | """ |
| 28 | |
| stevenvanrossem | e131bf5 | 2016-07-14 11:42:09 +0200 | [diff] [blame^] | 29 | |
| stevenvanrossem | 1a6843a | 2016-05-19 12:19:36 +0200 | [diff] [blame] | 30 | import requests |
| stevenvanrossem | e131bf5 | 2016-07-14 11:42:09 +0200 | [diff] [blame^] | 31 | |
| stevenvanrossem | 2fdfbf4 | 2016-05-13 15:08:47 +0200 | [diff] [blame] | 32 | |
| stevenvanrossem | 48db051 | 2016-05-18 15:43:24 +0200 | [diff] [blame] | 33 | # 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 |
| stevenvanrossem | e131bf5 | 2016-07-14 11:42:09 +0200 | [diff] [blame^] | 35 | #TODO if prometheus sdk DB is started outside of emulator, place these globals in an external SDK config file? |
| 36 | prometheus_ip = 'localhost' |
| 37 | # when sdk is started with docker-compose, we could use |
| 38 | # prometheus_ip = 'prometheus' |
| stevenvanrossem | 2fdfbf4 | 2016-05-13 15:08:47 +0200 | [diff] [blame] | 39 | prometheus_port = '9090' |
| 40 | prometheus_REST_api = 'http://{0}:{1}'.format(prometheus_ip, prometheus_port) |
| 41 | |
| 42 | |
| 43 | def query_Prometheus(query): |
| 44 | url = prometheus_REST_api + '/' + 'api/v1/query?query=' + query |
| 45 | # logging.info('query:{0}'.format(url)) |
| stevenvanrossem | 1a6843a | 2016-05-19 12:19:36 +0200 | [diff] [blame] | 46 | req = requests.get(url) |
| stevenvanrossem | 1a6843a | 2016-05-19 12:19:36 +0200 | [diff] [blame] | 47 | ret = req.json() |
| stevenvanrossem | 2fdfbf4 | 2016-05-13 15:08:47 +0200 | [diff] [blame] | 48 | 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 |