From: Kristoffer Grönlund Date: Thu, 27 Feb 2020 07:29:22 +0000 (+0100) Subject: mgr/cephadm: Configure Alertmanagers in Prometheus configuration X-Git-Tag: v15.1.1~208^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=accbe4500201031c9c0d458bcaf5470255fab9d1;p=ceph-ci.git mgr/cephadm: Configure Alertmanagers in Prometheus configuration 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 --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 40ab86a7c1f..7aee5918908 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) ), }, })