return j
def _generate_grafana_config(self):
- return json.dumps({
+ def generate_grafana_ds_config(hosts: List[str]) -> str:
+ config = '''# generated by cephadm
+deleteDatasources:
+{delete_data_sources}
+
+datasources:
+{data_sources}
+'''
+ delete_ds_template = '''
+ - name: '{name}'
+ orgId: 1\n'''.lstrip('\n')
+ ds_template = '''
+ - name: '{name}'
+ type: 'prometheus'
+ access: 'proxy'
+ orgId: 1
+ url: 'http://{host}:9095'
+ basicAuth: false
+ isDefault: {is_default}
+ editable: false\n'''.lstrip('\n')
+
+ delete_data_sources = ''
+ data_sources = ''
+ for i, host in enumerate(hosts):
+ name = "Dashboard %d" % (i + 1)
+ data_sources += ds_template.format(
+ name=name,
+ host=host,
+ is_default=str(i == 0).lower()
+ )
+ delete_data_sources += delete_ds_template.format(
+ name=name
+ )
+ return config.format(
+ delete_data_sources=delete_data_sources,
+ data_sources=data_sources,
+ )
+
+ prom_services = [ps.nodename for ps in self.cache.get_daemons_by_type('prometheus')]
+ config_file = json.dumps({
'files': {
"grafana.ini": """# generated by cephadm
[users]
admin_password = admin
allow_embedding = true
""",
- "provisioning/datasources/ceph-dashboard.yml": """# generated by cephadm
-deleteDatasources:
- - name: 'Dashboard'
- orgId: 1
-
-datasources:
- - name: 'Dashboard'
- type: 'prometheus'
- access: 'proxy'
- orgId: 1
- url: 'http://localhost:9095'
- basicAuth: false
- isDefault: true
- editable: false
-""",
+ 'provisioning/datasources/ceph-dashboard.yml': generate_grafana_ds_config(prom_services),
'certs/cert_file': '''# generated by cephadm
-----BEGIN CERTIFICATE-----
MIIDLTCCAhWgAwIBAgIUEH0mq6u93LKsWlNXst5pxWcuqkQwDQYJKoZIhvcNAQEL
-----END PRIVATE KEY-----''',
}
})
+ return config_file
def add_prometheus(self, spec):
return self._add_daemon('prometheus', spec, self._create_prometheus)