--- /dev/null
+global:
+ scrape_interval: 15s # By default, scrape targets every 15 seconds.
+ evaluation_interval: 5s
+
+
+# A scrape configuration containing endpoints to scrape:
+
+scrape_configs:
+
+# cAdvsior started in son-emu
+ - job_name: 'cAdvisor'
+
+ scrape_interval: 1s
+
+ target_groups:
+ - targets: ['172.17.0.1:8090']
+
+# Pushgateway started in SP
+ - job_name: 'PushGateway'
+
+ scrape_interval: 1s
+
+ target_groups:
+ - targets: ['172.17.0.1:9091']
+
+
--- /dev/null
+from setuptools import setup, find_packages
+
+setup(name='emuvim',
+ version='0.0.1',
+ license='Apache 2.0',
+ description='emuvim is a VIM for the SONATA platform',
+ url='http://github.com/sonata-emu',
+ author_email='sonata-dev@sonata-nfv.eu',
+ package_dir={'': 'src'},
+ # packages=find_packages('emuvim', exclude=['*.test', '*.test.*', 'test.*', 'test']),
+ packages=find_packages('src'),
+ install_requires=[
+ 'zerorpc',
+ 'tabulate',
+ 'argparse',
+ ],
+ zip_safe=False,
+ entry_points={
+ 'console_scripts': [
+ 'son-emu-cli=emuvim.cli.son_emu_cli:main',
+ ],
+ },
+ setup_requires=['pytest-runner'],
+ tests_require=['pytest'],
+)
\ No newline at end of file
nw_list = list()
if args.get("network") is not None:
nw_list = self._parse_network(args.get("network"))
-
r = self.c.compute_action_start(
args.get("datacenter"),
args.get("name"),
\r
import argparse\r
import pprint\r
-from tabulate import tabulate\r
import zerorpc\r
-import time\r
-\r
+import prometheus\r
\r
pp = pprint.PrettyPrinter(indent=4)\r
\r
class ZeroRpcClient(object):\r
\r
def __init__(self):\r
+ # network zerorpc\r
self.c = zerorpc.Client()\r
# TODO connect to DCNetwork API\r
#self.c.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later\r
self.c.connect("tcp://127.0.0.1:5151")\r
+\r
+ # compute zerorpc\r
+ self.compute_api = zerorpc.Client(heartbeat=None, timeout=120) # heartbeat=None, timeout=120\r
+ self.compute_api.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later\r
+\r
self.cmds = {}\r
\r
def execute_command(self, args):\r
args.get("cookie"))\r
pp.pprint(r)\r
\r
- def prometheus(self, args):\r
+ def prometheus_zrpc(self, args):\r
vnf_name = self._parse_vnf_name(args.get("vnf_name"))\r
vnf_interface = self._parse_vnf_interface(args.get("vnf_name"))\r
r = self.c.prometheus(\r
args.get("query"))\r
pp.pprint(r)\r
\r
+ def prometheus(self, args):\r
+ vnf_name = self._parse_vnf_name(args.get("vnf_name"))\r
+ vnf_interface = self._parse_vnf_interface(args.get("vnf_name"))\r
+ dc_label = args.get("datacenter")\r
+ query = args.get("query")\r
+ vnf_status = self.compute_api.compute_status(dc_label, vnf_name)\r
+ uuid = vnf_status['id']\r
+ query = query.replace('<uuid>', uuid)\r
+\r
+ r = prometheus.query_Prometheus(query)\r
+ pp.pprint(r)\r
+\r
\r
def _parse_vnf_name(self, vnf_name_str):\r
vnf_name = vnf_name_str.split(':')[0]\r
parser.add_argument(\r
"command",\r
choices=['setup_metric', 'stop_metric', 'setup_flow', 'stop_flow','prometheus'],\r
- help="setup/stop a metric/flow to be monitored or Prometheus query")\r
+ help="setup/stop a metric/flow to be monitored or query Prometheus")\r
parser.add_argument(\r
"--vnf_name", "-vnf", dest="vnf_name",\r
help="vnf name:interface to be monitored")\r
--- /dev/null
+"""
+Prometheus API helper functions
+(c) 2016 by Steven Van Rossem <steven.vanrossem@intec.ugent.be>
+"""
+
+import urllib2
+import ast
+
+prometheus_ip = '0.0.0.0'
+prometheus_port = '9090'
+prometheus_REST_api = 'http://{0}:{1}'.format(prometheus_ip, prometheus_port)
+
+
+def query_Prometheus(query):
+ url = prometheus_REST_api + '/' + 'api/v1/query?query=' + query
+ # logging.info('query:{0}'.format(url))
+ req = urllib2.Request(url)
+ ret = urllib2.urlopen(req).read()
+ ret = ast.literal_eval(ret)
+ if ret['status'] == 'success':
+ # logging.info('return:{0}'.format(ret))
+ try:
+ ret = ret['data']['result'][0]['value']
+ except:
+ ret = None
+ else:
+ ret = None
+ return ret
\ No newline at end of file
self.monitor_flow_thread.start()\r
\r
# helper tools\r
- self.pushgateway_process = self.start_PushGateway()\r
- self.prometheus_process = self.start_Prometheus()\r
+ #self.pushgateway_process = self.start_PushGateway()\r
+ #self.prometheus_process = self.start_Prometheus()\r
self.cadvisor_process = self.start_cadvisor()\r
\r
# first set some parameters, before measurement can start\r
self.monitor_thread.join()\r
self.monitor_flow_thread.join()\r
\r
+ '''\r
if self.prometheus_process is not None:\r
logging.info('stopping prometheus container')\r
self.prometheus_process.terminate()\r
self.pushgateway_process.terminate()\r
self.pushgateway_process.kill()\r
self._stop_container('pushgateway')\r
+ '''\r
\r
if self.cadvisor_process is not None:\r
logging.info('stopping cadvisor container')\r
--- /dev/null
+#!/bin/bash
+# test if a vnf can be monitored and deployed
+
+cpu_load=$(son-emu-cli monitor prometheus -d datacenter1 -vnf vnf1 -q 'sum(rate(container_cpu_usage_seconds_total{id="/docker/<uuid>"}[10s]))')
+
+# test if prometheus query worked
+regex="[0-9.]+, [0-9.']+"
+if [[ $cpu_load =~ $regex ]] ; then
+ echo "OK"
+ exit 0
+else
+ echo $cpu_load
+ echo "not OK"
+ exit 1
+fi