- @classmethod
- def _start_collectd(cls, connection, bin_path):
- connection.execute('pkill -9 collectd')
- collectd = os.path.join(bin_path, "collectd.sh")
- provision_tool(connection, collectd)
- provision_tool(connection, os.path.join(bin_path, "collectd.conf"))
+ def _provide_config_file(self, bin_path, nfvi_cfg, kwargs):
+ with open(os.path.join(bin_path, nfvi_cfg), 'r') as cfg:
+ template = cfg.read()
+ cfg, cfg_content = tempfile.mkstemp()
+ with os.fdopen(cfg, "w+") as cfg:
+ cfg.write(template.format(**kwargs))
+ cfg_file = os.path.join(bin_path, nfvi_cfg)
+ self.connection.put(cfg_content, cfg_file)
+
+ def _prepare_collectd_conf(self, bin_path):
+ """ Prepare collectd conf """
+ loadplugin = "\n".join("LoadPlugin {0}".format(plugin)
+ for plugin in LIST_PLUGINS_ENABLED)
+
+ interfaces = "\n".join("PortName '{0[name]}'".format(interface)
+ for interface in self.interfaces)
+
+ kwargs = {
+ "interval": '25',
+ "loadplugin": loadplugin,
+ "dpdk_interface": interfaces,
+ }
+
+ self._provide_config_file(bin_path, 'collectd.conf', kwargs)
+
+ def _start_collectd(self, connection, bin_path):
+ connection.execute('sudo pkill -9 collectd')
+ bin_path = get_nsb_option("bin_path")
+ collectd_path = os.path.join(bin_path, "collectd", "collectd")
+ exit_status = connection.execute("which %s > /dev/null 2>&1" % collectd_path)[0]
+ if exit_status != 0:
+ LOG.warning("%s is not present disabling", collectd_path)
+ # disable auto-provisioning because it requires Internet access
+ # collectd_installer = os.path.join(bin_path, "collectd.sh")
+ # provision_tool(connection, collectd)
+ # http_proxy = os.environ.get('http_proxy', '')
+ # https_proxy = os.environ.get('https_proxy', '')
+ # connection.execute("sudo %s '%s' '%s'" % (
+ # collectd_installer, http_proxy, https_proxy))
+ return
+ LOG.debug("Starting collectd to collect NFVi stats")
+ self._prepare_collectd_conf(bin_path)