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 assert from "node:assert";
import { join } from "node:path";
import { Alpine } from "../../alpine.js"; import { Alpine } from "../../alpine.js";
import { Runit } from "../../runit/index.js"; import { Runit } from "../../runit/index.js";
import { loadGrafanaSecretsFile } from "./secrets.js"; import { loadGrafanaSecretsFile } from "./secrets.js";
const provisioningDir = "/etc/grafana/provisioning/";
// TODO: grafana-image-renderer? // TODO: grafana-image-renderer?
// /etc/conf.d/grafana // /etc/conf.d/grafana
// # To enable image rendering run // # 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("/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( await alpine.sudoWriteExecutable(
"/usr/local/sbin/nulo-grafana-cli", "/usr/local/sbin/nulo-grafana-cli",
`#!/bin/sh `#!/bin/sh
@ -45,16 +62,7 @@ export GRAFANA_HOME=/var/lib/grafana
cd "$GRAFANA_HOME" cd "$GRAFANA_HOME"
install -o grafana -m755 -d \ exec chpst -u grafana:grafana grafana-server -config /etc/grafana.ini -homepath /usr/share/grafana
$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
` `
); );
} }
@ -81,7 +89,7 @@ data = /var/lib/grafana
plugins = /var/lib/grafana/plugins plugins = /var/lib/grafana/plugins
# folder that contains provisioning config files that grafana will apply on startup and while running. # folder that contains provisioning config files that grafana will apply on startup and while running.
;provisioning = conf/provisioning provisioning = ${provisioningDir}
#################################### Server #################################### #################################### Server ####################################
[server] [server]