From: Nizamudeen A Date: Fri, 16 Feb 2024 07:58:06 +0000 (+0530) Subject: mgr/cephadm: mount grafana dashboards from the path X-Git-Tag: v19.1.0~168^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1813eba9fc317f254b06ef757eb288061edbea9a;p=ceph.git mgr/cephadm: mount grafana dashboards from the path 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 (cherry picked from commit 2a112acd0a40ceed173e3b168ea30da5c31b27ad) --- diff --git a/ceph.spec.in b/ceph.spec.in index ed3674655277..24b8b1f6123f 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -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 diff --git a/debian/rules b/debian/rules index ed7f4a255ed4..442ea28d4e0b 100755 --- a/debian/rules +++ b/debian/rules @@ -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: diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 5a7ed9e76656..47842d09da17 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -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' diff --git a/src/cephadm/cephadmlib/constants.py b/src/cephadm/cephadmlib/constants.py index dfa660f48986..e53de90d0858 100644 --- a/src/cephadm/cephadmlib/constants.py +++ b/src/cephadm/cephadmlib/constants.py @@ -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' diff --git a/src/cephadm/cephadmlib/daemons/monitoring.py b/src/cephadm/cephadmlib/daemons/monitoring.py index e0667853dd7b..2ba6da289c28 100644 --- a/src/cephadm/cephadmlib/daemons/monitoring.py +++ b/src/cephadm/cephadmlib/daemons/monitoring.py @@ -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' diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 87f7024bb255..fc60de433ccc 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -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 diff --git a/src/pybind/mgr/cephadm/services/monitoring.py b/src/pybind/mgr/cephadm/services/monitoring.py index 114c848608a3..28da2f7558bc 100644 --- a/src/pybind/mgr/cephadm/services/monitoring.py +++ b/src/pybind/mgr/cephadm/services/monitoring.py @@ -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 index 000000000000..6c284daeb67d --- /dev/null +++ b/src/pybind/mgr/cephadm/templates/services/grafana/providers.yml.j2 @@ -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'