Skip to content

Commit

Permalink
Merge pull request #84 from mpeuster/master
Browse files Browse the repository at this point in the history
Added auto start/stop for prometheus #80
  • Loading branch information
Manuel Peuster committed Apr 17, 2019
2 parents c27e0e8 + 646d53f commit 7dab84a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/tngsdk/benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
import coloredlogs
import time
import shutil
import subprocess
from tngsdk.benchmark.experiment import ServiceExperiment, FunctionExperiment
from tngsdk.benchmark.generator.sonata \
import SonataServiceConfigurationGenerator
from tngsdk.benchmark.generator.tango \
import TangoServiceConfigurationGenerator
from tngsdk.benchmark.executor import Executor
from tngsdk.benchmark.helper import read_yaml
from tngsdk.benchmark.helper import read_yaml, get_prometheus_path
from tngsdk.benchmark.resultprocessor.ietfbmwg import IetfBmwgResultProcessor
from tngsdk.benchmark.resultprocessor.vimemu import VimemuResultProcessor
from tngsdk.benchmark.logger import TangoLogger
Expand Down Expand Up @@ -114,9 +115,11 @@ def run(self):
if self.cgen is None:
return
self.generate_experiments()
self.start_prometheus_monitoring()
self.execute_experiments()
self.process_results()
self.copy_ped()
self.stop_prometheus_monitoring()

def check_rd_existence(self):
if os.path.exists(self.args.result_dir):
Expand All @@ -133,6 +136,35 @@ def check_rd_existence(self):
self.logger.info("Overwriting old results: {}"
.format(self.args.result_dir))
shutil.rmtree(self.args.result_dir)
# also clean prometheus data (if present, rquires sudo)
try:
pm_path = get_prometheus_path()
self.logger.info("Removing Prometheus data: {}"
.format(pm_path))
subprocess.call(["./clean.sh"], cwd=pm_path)
except BaseException as ex:
self.logger.warning("Couldn't remove Prometheus data: {}"
.format(ex))

def start_prometheus_monitoring(self):
try:
pm_path = get_prometheus_path()
self.logger.info("Starting Prometheus 'docker-compose up in:' {}"
.format(pm_path))
subprocess.call(["docker-compose", "up", "-d"], cwd=pm_path)
except BaseException as ex:
self.logger.warning("Couldn't start Prometheus. Skipping it. ({})"
.format(ex))

def stop_prometheus_monitoring(self):
try:
pm_path = get_prometheus_path()
self.logger.info("Stopping Prometheus 'docker-compose down in:' {}"
.format(pm_path))
subprocess.call(["docker-compose", "down"], cwd=pm_path)
except BaseException as ex:
self.logger.warning("Couldn't stop Prometheus. Skipping it. ({})"
.format(ex))

def populate_experiments(self):
if self.args.no_population:
Expand Down
17 changes: 17 additions & 0 deletions src/tngsdk/benchmark/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,20 @@ def dubunderscore_reducer(k1, k2):
return k2
else:
return k1 + "__" + k2


def get_prometheus_path():
"""
Returns the absolute path to the
Prometheus fodler of the used tng-bench
installation.
"""
try:
p = os.path.dirname(os.path.abspath(__file__))
p = os.path.join(p, "../../../prometheus")
if os.path.exists(p):
return os.path.abspath(p)
raise BaseException("Prometheus path {} not found".format(p))
except BaseException as ex:
LOG.warning("Couldn't find prometheus path: {}".format(ex))
return None

0 comments on commit 7dab84a

Please sign in to comment.