aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2021-07-13 21:38:50 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2021-07-13 21:38:50 +0200
commit345a65fc563332289b2e997febddff8ac0612457 (patch)
tree9f53c88c71b9b9d592f2e8b00bbe1e7be291c99d
parentb92f65ece3cd38365bdfe11a82780913adee8ddb (diff)
downloadrumba-345a65fc563332289b2e997febddff8ac0612457.zip
rumba-345a65fc563332289b2e997febddff8ac0612457.tar.gz
prototypes: Add metrics install for ouroboros
This allows specifying an InfluxDB server for the experiment. The prototype will then install and configure the metrics exporter.
-rw-r--r--rumba/prototypes/ouroboros.py115
1 files changed, 112 insertions, 3 deletions
diff --git a/rumba/prototypes/ouroboros.py b/rumba/prototypes/ouroboros.py
index 727a05c..eb6a230 100644
--- a/rumba/prototypes/ouroboros.py
+++ b/rumba/prototypes/ouroboros.py
@@ -96,7 +96,8 @@ class Experiment(mod.Experiment):
build_options='',
add_packages=[],
enrollment_strategy='minimal',
- flows_strategy='full-mesh'):
+ flows_strategy='full-mesh',
+ influxdb=None):
"""
Initializes the experiment class.
@@ -107,7 +108,14 @@ class Experiment(mod.Experiment):
:param build_options: Options for CMake building
:param add_packages: Additional packages to be installed.
:param enrollment_strategy: Can be 'full-mesh', 'minimal' or 'manual'.
- :param strategy: For flows, 'full-mesh', 'minimal' or 'manual'.
+ :param flows_strategy: For flows, 'full-mesh', 'minimal' or 'manual'.
+ :param influxdb: dict with information for InfluxDB database
+ {
+ "ip": <IP address for InfluxDB database>,
+ "port": <TCP port for InfluxDB database>,
+ "org": <Organization in InfluxDB database>,
+ "token": <Token to access InfluxDB database>
+ }
"""
mod.Experiment.__init__(
self,
@@ -121,9 +129,17 @@ class Experiment(mod.Experiment):
flows_strategy=flows_strategy,
server_decorator=OurServer
)
- self.r_ipcps = dict()
+ _required = ['ip', 'port', 'org', 'token']
+ for field in _required:
+ if field not in influxdb:
+ raise(Exception("Missing field %s in influx_db: %s" % field))
+
+ self.r_ipcps = dict()
+ self.irmd = None
+ self.influxdb = influxdb
self.set_startup_command("irmd")
+ self.metrics_python_version = "python3.9"
@staticmethod
def make_executor(node, packages, testbed):
@@ -189,6 +205,96 @@ class Experiment(mod.Experiment):
args.append(cmds)
m_processing.call_in_parallel(names, args, executors)
+ def _install_python_ppa(self):
+ packages = ["software-properties-common"]
+ python_ppa = "ppa:deadsnakes/ppa"
+ cmds = ["sudo add-apt-repository {} -y".format(python_ppa),
+ "sudo apt-get update"]
+
+ names = []
+ args = []
+ executors = []
+
+ for node in self.nodes:
+ executor = self.make_executor(node, packages, self.testbed)
+ names.append(node.name)
+ executors.append(executor)
+ args.append(cmds)
+
+ m_processing.call_in_parallel(names, args, executors)
+
+ def _install_python_version(self, python_version):
+ python_packages = ["distutils", "venv"]
+ python_libs = ["dev"]
+
+ packages = [python_version]
+ for package in python_packages:
+ packages += [python_version + "-" + package]
+
+ for lib in python_libs:
+ packages += ["lib" + python_version + "-" + lib]
+
+ cmds = []
+
+ names = []
+ args = []
+ executors = []
+
+ for node in self.nodes:
+ executor = self.make_executor(node, packages, self.testbed)
+ names.append(node.name)
+ executors.append(executor)
+ args.append(cmds)
+
+ m_processing.call_in_parallel(names, args, executors)
+
+ def install_ouroboros_python_exporter(self):
+ if isinstance(self.testbed, local.Testbed):
+ return
+
+ if self.influxdb is None:
+ return
+
+ python_version = self.metrics_python_version
+ python_cmd = "venv/bin/" + python_version
+
+ self._install_python_ppa()
+ self._install_python_version(python_version)
+
+ cmds = [python_version + " -m venv venv",
+ python_cmd + " -m easy_install pip",
+ python_cmd + " -m pip install 'influxdb-client[ciso]'"]
+
+ # Patch the influxDB install from my repository. Temporary until 1.20 is in PyPi
+ cmds += ["git clone https://github.com/dstaesse/influxdb-client-python.git",
+ "sudo cp influxdb-client-python/influxdb_client/client/influxdb_client.py" # no comma: concat!
+ " ~/venv/lib/" + python_version + "/site-packages/influxdb_client/client/influxdb_client.py"]
+
+ # Clone the metrics exporter repo and get the exporter
+ cmds += ["git clone https://ouroboros.rocks/git/ouroboros-metrics",
+ "cp ouroboros-metrics/exporters-influxdb/pyExporter/oexport.py .",
+ "rm -rf ouroboros-metrics"]
+
+ # Write the configuration file
+ cmds += ["echo [influx2] > config.ini",
+ "echo 'url=http://" + self.influxdb['ip'] + ":" + str(self.influxdb['port']) + "' >> config.ini",
+ "echo 'org=" + self.influxdb['org'] + "' >> config.ini",
+ "echo 'token=" + self.influxdb['token'] + "' >> config.ini",
+ "echo 'timeout=6000' >> config.ini",
+ 'echo "proxy=$http_proxy" >> config.ini',
+ "echo 'verify_ssl=False' >> config.ini"]
+ names = []
+ executors = []
+ args = []
+
+ for node in self.nodes:
+ executor = self.make_executor(node, [], self.testbed)
+ names.append(node.name)
+ args.append(cmds)
+ executors.append(executor)
+
+ m_processing.call_in_parallel(names, args, executors)
+
def create_ipcps(self):
for node in self.nodes:
cmds = list()
@@ -291,6 +397,9 @@ class Experiment(mod.Experiment):
def _install_prototype(self):
logger.info("Installing Ouroboros...")
self.install_ouroboros()
+ if self.influxdb:
+ logger.info("Installing Ouroboros metrics exporter")
+ self.install_ouroboros_python_exporter()
logger.info("Installed on all nodes...")
def _bootstrap_prototype(self):