Skip to content

Commit

Permalink
mgr/cephadm: mount grafana dashboards from the path
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nizamial09 committed Mar 8, 2024
1 parent 0debdf6 commit 2a112ac
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ceph.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/cephadm/cephadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/cephadm/cephadmlib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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'
Expand Down
3 changes: 3 additions & 0 deletions src/cephadm/cephadmlib/daemons/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ def _get_container_mounts(self, data_dir: str) -> Dict[str, str]:
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'
Expand Down
9 changes: 8 additions & 1 deletion src/pybind/mgr/cephadm/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def os_exit_noop(status: int) -> None:
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'
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -549,6 +555,7 @@ def __init__(self, *args: Any, **kwargs: Any):
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
Expand Down
18 changes: 18 additions & 0 deletions src/pybind/mgr/cephadm/services/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,33 @@ def generate_config(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[Dict[st
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': {
"grafana.ini": grafana_ini,
'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]:
Expand Down
13 changes: 13 additions & 0 deletions src/pybind/mgr/cephadm/templates/services/grafana/providers.yml.j2
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 2a112ac

Please sign in to comment.