From ab59bc345de1a2e87c7fe40ef49cce36df7f893f Mon Sep 17 00:00:00 2001 From: Molly Miller Date: Tue, 10 Sep 2024 15:43:23 +0200 Subject: [PATCH] statshost: add loki data source to grafana configuration If the loki role is also enabled on the same host as statshost-master, then add a Loki data source to the Grafana configuration. PL-132981 --- nixos/roles/statshost/default.nix | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/nixos/roles/statshost/default.nix b/nixos/roles/statshost/default.nix index 2f0d980ac..3c6ca8a3a 100644 --- a/nixos/roles/statshost/default.nix +++ b/nixos/roles/statshost/default.nix @@ -18,6 +18,8 @@ let cfgProxyLocation = config.flyingcircus.roles.statshost-location-proxy; cfgProxyRG = config.flyingcircus.roles.statshost-relay; + cfgLokiRG = config.flyingcircus.roles.loki; + promFlags = [ "--storage.tsdb.retention.time ${toString cfgStats.prometheusRetention}d" ]; @@ -517,12 +519,30 @@ in isDefault: true ''; }; + + # support loki running on the same host as grafana in + # single-RG mode. + lokiDatasource = pkgs.writeTextFile { + name = "loki.yaml"; + text = '' + apiVersion: 1 + datasources: + - name: Loki + type: loki + access: proxy + orgId: 1 + url: http://${config.networking.hostName}:3100 + editable: false + isDefault: false + ''; + }; in '' rm -rf ${grafanaProvisioningPath} mkdir -p ${grafanaProvisioningPath}/dashboards ${grafanaProvisioningPath}/datasources ln -fs ${fcioDashboards} ${grafanaProvisioningPath}/dashboards/fcio.yaml ln -fs ${prometheusDatasource} ${grafanaProvisioningPath}/datasources/prometheus.yaml - + '' + optionalString (cfgStatsRG.enable && cfgLokiRG.enable) '' + ln -fs ${lokiDatasource} ${grafanaProvisioningPath}/datasources/loki.yaml ''; # Provide FC dashboards, and update them automatically.