From: Sage Weil Date: Thu, 20 Feb 2020 20:13:04 +0000 (-0600) Subject: mgr/cephadm: make prometheus scrape all node-exporters X-Git-Tag: v15.1.1~330^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e9f78a358f7911b124c6ca373456cd51020ca96d;p=ceph.git mgr/cephadm: make prometheus scrape all node-exporters Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 744071bd9968..278e1d6fd2d6 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), ), }, })