]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: mount grafana dashboards from the path
authorNizamudeen A <nia@redhat.com>
Fri, 16 Feb 2024 07:58:06 +0000 (13:28 +0530)
committerNizamudeen A <nia@redhat.com>
Fri, 8 Mar 2024 10:21:08 +0000 (15:51 +0530)
For this, the grafana dashboards are installed directly to the
containers and later, cephadm picks it up to mount the dashboards to the
grafana container

Signed-off-by: Nizamudeen A <nia@redhat.com>
ceph.spec.in
debian/rules
src/cephadm/cephadm.py
src/cephadm/cephadmlib/constants.py
src/cephadm/cephadmlib/daemons/monitoring.py
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/services/monitoring.py
src/pybind/mgr/cephadm/templates/services/grafana/providers.yml.j2 [new file with mode: 0644]

index ed36746552776f5194cf6bc5e823f6e29510d02d..24b8b1f6123f710895660e9cfb081dd3f0ad3057 100644 (file)
@@ -1572,6 +1572,9 @@ mkdir -p %{buildroot}%{_localstatedir}/lib/ceph/bootstrap-rbd-mirror
 # prometheus alerts
 install -m 644 -D monitoring/ceph-mixin/prometheus_alerts.yml %{buildroot}/etc/prometheus/ceph/ceph_default_alerts.yml
 
+# grafana charts
+install -m 644 -D monitoring/ceph-mixin/dashboards_out/* %{buildroot}/etc/grafana/dashboards/ceph-dashboard/
+
 # SNMP MIB
 install -m 644 -D -t %{buildroot}%{_datadir}/snmp/mibs monitoring/snmp/CEPH-MIB.txt
 
index ed7f4a255ed4b798d710714ee368ef973c42abb6..442ea28d4e0b0291376a10de1424ff8ca2c7f5db 100755 (executable)
@@ -77,6 +77,7 @@ override_dh_auto_install:
        install -D -m 755 src/tools/rbd_nbd/rbd-nbd_quiesce $(DESTDIR)/usr/libexec/rbd-nbd/rbd-nbd_quiesce
 
        install -m 644 -D monitoring/ceph-mixin/prometheus_alerts.yml $(DESTDIR)/etc/prometheus/ceph/ceph_default_alerts.yml
+       install -m 644 -D monitoring/ceph-mixin/dashboards_out/* ${DESTDIR}/etc/grafana/dashboards/ceph-dashboard
 
 # doc/changelog is a directory, which confuses dh_installchangelogs
 override_dh_installchangelogs:
index 5a7ed9e766569e0d7446fe9041eee51667d337f3..47842d09da1738ed915672ed47d5038ac3095891 100755 (executable)
@@ -736,8 +736,10 @@ def create_daemon_dirs(
             makedirs(os.path.join(data_dir_root, config_dir), uid, gid, 0o755)
             makedirs(os.path.join(data_dir_root, config_dir, 'certs'), uid, gid, 0o755)
             makedirs(os.path.join(data_dir_root, config_dir, 'provisioning/datasources'), uid, gid, 0o755)
-            makedirs(os.path.join(data_dir_root, 'data'), uid, gid, 0o755)
+            makedirs(os.path.join(data_dir_root, config_dir, 'provisioning/dashboards'), uid, gid, 0o755)
+            makedirs(os.path.join(data_dir_root, 'data'), uid, gid, 0o472)
             touch(os.path.join(data_dir_root, 'data', 'grafana.db'), uid, gid)
+            recursive_chown(os.path.join(data_dir_root, 'data'), uid, gid)
         elif daemon_type == 'alertmanager':
             data_dir_root = ident.data_dir(ctx.data_dir)
             config_dir = 'etc/alertmanager'
index dfa660f48986338e46a656c7c31f80c7837aefc6..e53de90d0858f369812411519e676534a7ccaea5 100644 (file)
@@ -9,7 +9,7 @@ DEFAULT_LOKI_IMAGE = 'docker.io/grafana/loki:2.4.0'
 DEFAULT_PROMTAIL_IMAGE = 'docker.io/grafana/promtail:2.4.0'
 DEFAULT_NODE_EXPORTER_IMAGE = 'quay.io/prometheus/node-exporter:v1.5.0'
 DEFAULT_ALERT_MANAGER_IMAGE = 'quay.io/prometheus/alertmanager:v0.25.0'
-DEFAULT_GRAFANA_IMAGE = 'quay.io/ceph/ceph-grafana:9.4.12'
+DEFAULT_GRAFANA_IMAGE = 'quay.io/ceph/grafana:9.4.12'
 DEFAULT_HAPROXY_IMAGE = 'quay.io/ceph/haproxy:2.3'
 DEFAULT_KEEPALIVED_IMAGE = 'quay.io/ceph/keepalived:2.2.4'
 DEFAULT_NVMEOF_IMAGE = 'quay.io/ceph/nvmeof:latest'
index e0667853dd7b5732c02d718458ef2e98d5924949..2ba6da289c28f064fc54b22cefff064d98be1876 100644 (file)
@@ -333,6 +333,9 @@ class Monitoring(ContainerDaemonForm):
             mounts[
                 os.path.join(data_dir, 'etc/grafana/provisioning/datasources')
             ] = '/etc/grafana/provisioning/datasources:Z'
+            mounts[
+                os.path.join(data_dir, 'etc/grafana/provisioning/dashboards')
+            ] = '/etc/grafana/provisioning/dashboards:Z'
             mounts[
                 os.path.join(data_dir, 'etc/grafana/certs')
             ] = '/etc/grafana/certs:Z'
index 87f7024bb2555510a7418f357634559a2bed0593..fc60de433ccc4f433c5dcf4b86760ddcf30cca60 100644 (file)
@@ -121,7 +121,7 @@ DEFAULT_NVMEOF_IMAGE = 'quay.io/ceph/nvmeof:latest'
 DEFAULT_LOKI_IMAGE = 'docker.io/grafana/loki:2.4.0'
 DEFAULT_PROMTAIL_IMAGE = 'docker.io/grafana/promtail:2.4.0'
 DEFAULT_ALERT_MANAGER_IMAGE = 'quay.io/prometheus/alertmanager:v0.25.0'
-DEFAULT_GRAFANA_IMAGE = 'quay.io/ceph/ceph-grafana:9.4.12'
+DEFAULT_GRAFANA_IMAGE = 'quay.io/ceph/grafana:9.4.12'
 DEFAULT_HAPROXY_IMAGE = 'quay.io/ceph/haproxy:2.3'
 DEFAULT_KEEPALIVED_IMAGE = 'quay.io/ceph/keepalived:2.2.4'
 DEFAULT_SNMP_GATEWAY_IMAGE = 'docker.io/maxwo/snmp-notifier:v1.2.1'
@@ -333,6 +333,12 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
             default='/etc/prometheus/ceph/ceph_default_alerts.yml',
             desc='location of alerts to include in prometheus deployments',
         ),
+        Option(
+            'grafana_dashboards_path',
+            type='str',
+            default='/etc/grafana/dashboards/ceph-dashboard/',
+            desc='location of dashboards to include in grafana deployments',
+        ),
         Option(
             'migration_current',
             type='int',
@@ -549,6 +555,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
             self.allow_ptrace = False
             self.container_init = True
             self.prometheus_alerts_path = ''
+            self.grafana_dashboards_path = ''
             self.migration_current: Optional[int] = None
             self.config_dashboard = True
             self.manage_etc_ceph_ceph_conf = True
index 114c848608a307a19b8eee94287892e681603d81..28da2f7558bcf01a02fb2ff88dde718705264551 100644 (file)
@@ -80,6 +80,14 @@ class GrafanaService(CephadmService):
             self.mgr.check_mon_command(
                 {'prefix': 'dashboard set-grafana-api-password'}, inbuf=spec.initial_admin_password)
 
+        # the path of the grafana dashboards are assumed from the providers.yml.j2 file by grafana
+        grafana_dashboards_path = self.mgr.grafana_dashboards_path or '/etc/grafana/dashboards/ceph-dashboard/'
+        grafana_providers = self.mgr.template.render(
+            'services/grafana/providers.yml.j2', {
+                'grafana_dashboards_path': grafana_dashboards_path
+            }
+        )
+
         cert, pkey = self.prepare_certificates(daemon_spec)
         config_file = {
             'files': {
@@ -87,8 +95,18 @@ class GrafanaService(CephadmService):
                 'provisioning/datasources/ceph-dashboard.yml': grafana_data_sources,
                 'certs/cert_file': '# generated by cephadm\n%s' % cert,
                 'certs/cert_key': '# generated by cephadm\n%s' % pkey,
+                'provisioning/dashboards/default.yml': grafana_providers
             }
         }
+
+        # include dashboards, if present in the container
+        if os.path.exists(grafana_dashboards_path):
+            files = os.listdir(grafana_dashboards_path)
+            for file_name in files:
+                with open(os.path.join(grafana_dashboards_path, file_name), 'r', encoding='utf-8') as f:
+                    dashboard = f.read()
+                    config_file['files'][f'/etc/grafana/provisioning/dashboards/{file_name}'] = dashboard
+
         return config_file, sorted(deps)
 
     def prepare_certificates(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[str, str]:
diff --git a/src/pybind/mgr/cephadm/templates/services/grafana/providers.yml.j2 b/src/pybind/mgr/cephadm/templates/services/grafana/providers.yml.j2
new file mode 100644 (file)
index 0000000..6c284da
--- /dev/null
@@ -0,0 +1,13 @@
+# {{ cephadm_managed }}
+apiVersion: 1
+
+providers:
+  - name: 'Ceph Dashboard'
+    orgId: 1
+    folder: ''
+    type: file
+    disableDeletion: false
+    updateIntervalSeconds: 3
+    editable: false
+    options:
+      path: '/etc/grafana/provisioning/dashboards'