From accbe4500201031c9c0d458bcaf5470255fab9d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristoffer=20Gr=C3=B6nlund?= Date: Thu, 27 Feb 2020 08:29:22 +0100 Subject: [PATCH] mgr/cephadm: Configure Alertmanagers in Prometheus configuration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This will configure Prometheus with any alertmanager daemons that have already been created. TODO: Currently the Prometheus configuration is not updated if additional alertmanager daemons are created. Signed-off-by: Kristoffer Grönlund --- src/pybind/mgr/cephadm/module.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 40ab86a7c1f10..7aee591890840 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2226,6 +2226,26 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): instance: '{}' """.format([addr.split(':')[0] + ':9100'], dd.hostname) + + # scrape alert managers + alertmgr_configs = "" + alertmgr_targets = [] + for dd in self.cache.get_daemons_by_service('alertmanager'): + hi = self.inventory.get(dd.hostname, None) + if hi is None: + continue + addr = hi.get('addr', dd.hostname) + alertmgr_targets.append("'{}:9093'".format(addr.split(':')[0])) + if alertmgr_targets: + alertmgr_configs = """alerting: + alertmanagers: + - scheme: http + path_prefix: /alertmanager + static_configs: + - targets: [{}] +""".format(", ".join(alertmgr_targets)) + + # generate the prometheus configuration j = json.dumps({ 'files': { 'prometheus.yml': """# generated by cephadm @@ -2234,6 +2254,7 @@ global: evaluation_interval: 10s rule_files: - /etc/prometheus/alerting/* +{alertmgr_configs} scrape_configs: - job_name: 'ceph' static_configs: @@ -2244,6 +2265,7 @@ scrape_configs: """.format( mgr_scrape_list=str(mgr_scrape_list), node_configs=str(node_configs), + alertmgr_configs=str(alertmgr_configs) ), }, }) -- 2.39.5