]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: make prometheus scrape all node-exporters
authorSage Weil <sage@redhat.com>
Thu, 20 Feb 2020 20:13:04 +0000 (14:13 -0600)
committerSage Weil <sage@redhat.com>
Thu, 20 Feb 2020 22:11:34 +0000 (16:11 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py

index 744071bd9968ae8b5ffbbdfbb8cc5e88868b6f96..278e1d6fd2d6effdd06e107dd1fa5396923f6fd8 100644 (file)
@@ -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),
     ),
             },
         })