From 9ec1874b24130d470c55c54c3a4eaaf2905bcfc9 Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Mon, 31 Jan 2022 17:35:31 +0530 Subject: [PATCH] mgr/dashboard: add Loki to grafana datasources Signed-off-by: Avan Thakkar Co-authored-by: Aashish Sharma (cherry picked from commit 66b2f03e8a028dd692ec95a0f97f3183a4bc8b56) --- src/cephadm/cephadm | 2 +- src/pybind/mgr/cephadm/services/monitoring.py | 7 ++++++- .../services/grafana/ceph-dashboard.yml.j2 | 13 +++++++++++++ .../services/grafana/loki-datasource.yml.j2 | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/pybind/mgr/cephadm/templates/services/grafana/loki-datasource.yml.j2 diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index f732857e18a7e..f8966b26de74c 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -550,7 +550,7 @@ class Monitoring(object): '--config.file=/etc/loki/loki.yml', ], 'config-json-files': [ - 'loki.yml', + 'loki.yml' ], }, 'promtail': { diff --git a/src/pybind/mgr/cephadm/services/monitoring.py b/src/pybind/mgr/cephadm/services/monitoring.py index d7a057cddef14..ed165b9f1be0f 100644 --- a/src/pybind/mgr/cephadm/services/monitoring.py +++ b/src/pybind/mgr/cephadm/services/monitoring.py @@ -36,8 +36,13 @@ class GrafanaService(CephadmService): prom_services.append(build_url(scheme='http', host=addr, port=port)) deps.append(dd.name()) + + loki_services = [] # type: List[str] + for dd in self.mgr.cache.get_daemons_by_service('mgr'): + addr = self.mgr.inventory.get_addr(dd.hostname) + loki_services.append(build_url(scheme='http', host=addr, port=3100)) grafana_data_sources = self.mgr.template.render( - 'services/grafana/ceph-dashboard.yml.j2', {'hosts': prom_services}) + 'services/grafana/ceph-dashboard.yml.j2', {'hosts': prom_services, 'loki_hosts': loki_services}) cert = self.mgr.get_store('grafana_crt') pkey = self.mgr.get_store('grafana_key') diff --git a/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 b/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 index 170e6f246f6df..95c3ca28cc433 100644 --- a/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 +++ b/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 @@ -4,6 +4,10 @@ deleteDatasources: - name: 'Dashboard{{ loop.index }}' orgId: 1 {% endfor %} +{% for loki_host in loki_hosts %} + - name: 'Loki{{ loop.index }}' + orgId: 1 +{% endfor %} datasources: {% for host in hosts %} @@ -16,3 +20,12 @@ datasources: isDefault: {{ 'true' if loop.first else 'false' }} editable: false {% endfor %} + + - name: 'Loki' + type: 'loki' + access: 'proxy' + orgId: 1 + url: '{{ loki_hosts[0] }}' + basicAuth: false + isDefault: true + editable: false diff --git a/src/pybind/mgr/cephadm/templates/services/grafana/loki-datasource.yml.j2 b/src/pybind/mgr/cephadm/templates/services/grafana/loki-datasource.yml.j2 new file mode 100644 index 0000000000000..7f8623d946aa1 --- /dev/null +++ b/src/pybind/mgr/cephadm/templates/services/grafana/loki-datasource.yml.j2 @@ -0,0 +1,16 @@ +# {{ cephadm_managed }} +deleteDatasources: +{% for loki_host in loki_hosts %} + - name: 'Loki{{ loop.index }}' + orgId: 1 +{% endfor %} + +datasources: + - name: 'Loki{{ loop.index }}' + type: 'loki' + access: 'proxy' + orgId: 1 + url: '{{ loki_hosts }}' + basicAuth: false + isDefault: {{ 'true' if loop.first else 'false' }} + editable: false -- 2.39.5