grafana: provision loki

This commit is contained in:
Cat /dev/Nulo 2023-02-19 12:05:00 -03:00
parent 9cb709bdd0
commit 8cba1d2bd0

View file

@ -1,8 +1,11 @@
import assert from "node:assert";
import { join } from "node:path";
import { Alpine } from "../../alpine.js";
import { Runit } from "../../runit/index.js";
import { loadGrafanaSecretsFile } from "./secrets.js";
const provisioningDir = "/etc/grafana/provisioning/";
// TODO: grafana-image-renderer?
// /etc/conf.d/grafana
// # To enable image rendering run
@ -31,6 +34,20 @@ export async function setupGrafana(
});
await alpine.writeFile("/etc/grafana.ini", await genConfig(), user);
await alpine.writeFile(
join(provisioningDir, "datasources/loki.yaml"),
`
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://localhost:3100
`,
user
);
await alpine.sudoWriteExecutable(
"/usr/local/sbin/nulo-grafana-cli",
`#!/bin/sh
@ -45,16 +62,7 @@ export GRAFANA_HOME=/var/lib/grafana
cd "$GRAFANA_HOME"
install -o grafana -m755 -d \
$GRAFANA_HOME/provisioning \
$GRAFANA_HOME/provisioning/dashboards \
$GRAFANA_HOME/provisioning/datasources \
$GRAFANA_HOME/provisioning/notifiers \
$GRAFANA_HOME/provisioning/alerting \
$GRAFANA_HOME/provisioning/plugins
exec chpst -u grafana:grafana grafana-server -config /etc/grafana.ini -homepath /usr/share/grafana \
cfg:paths.provisioning="$GRAFANA_HOME"/provisioning
exec chpst -u grafana:grafana grafana-server -config /etc/grafana.ini -homepath /usr/share/grafana
`
);
}
@ -81,7 +89,7 @@ data = /var/lib/grafana
plugins = /var/lib/grafana/plugins
# folder that contains provisioning config files that grafana will apply on startup and while running.
;provisioning = conf/provisioning
provisioning = ${provisioningDir}
#################################### Server ####################################
[server]