From e9f78a358f7911b124c6ca373456cd51020ca96d Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 20 Feb 2020 14:13:04 -0600 Subject: [PATCH] mgr/cephadm: make prometheus scrape all node-exporters Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 744071bd996..278e1d6fd2d 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2242,13 +2242,31 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return self._update_service('rbd-mirror', self.add_rbd_mirror, spec) def _generate_prometheus_config(self): + # scrape mgrs + # *** FIXME *** we should scrape all mgrs here *** mgr_map = self.get('mgr_map') mgr_scrape_list = [] - # *** FIXME *** we should scrape all mgrs here *** t = mgr_map.get('services', {}).get('prometheus', None) if t: t = t.split('/')[2] mgr_scrape_list = [t] + + # scrape node exporters + node_configs = '' + for dd in self.cache.get_daemons_by_type('node-exporter'): + hi = self.inventory.get(dd.nodename, None) + if hi: + addr = hi.get('addr', dd.nodename) + if not node_configs: + node_configs = """ + - job_name: 'node' + static_configs: +""" + node_configs += """ - targets: {} + labels: + instance: '{}' +""".format([addr.split(':')[0] + ':9100'], + dd.nodename) j = json.dumps({ 'files': { 'prometheus.yml': """# generated by cephadm @@ -2261,8 +2279,12 @@ scrape_configs: - job_name: 'ceph' static_configs: - targets: {mgr_scrape_list} + labels: + instance: 'ceph_cluster' +{node_configs} """.format( - mgr_scrape_list=str(mgr_scrape_list) + mgr_scrape_list=str(mgr_scrape_list), + node_configs=str(node_configs), ), }, }) -- 2.39.5