Skip to content

Commit

Permalink
statshost: add loki data source to grafana configuration
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sysvinit committed Sep 11, 2024
1 parent 18b49c9 commit ab59bc3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion nixos/roles/statshost/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ab59bc3

Please sign in to comment.