summaryrefslogtreecommitdiff
path: root/nixos/hosts/tente/grafana.nix
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2025-08-30 19:27:25 +0200
committerMartin Fischer <martin@push-f.com>2025-08-30 20:03:15 +0200
commit80a98992584487a389900ea9e78963c01ea3d812 (patch)
treee5b254c6d7956e2d181375847904766b2a3af586 /nixos/hosts/tente/grafana.nix
parent0c1ab2a61849a92f8df4170b934a3cdc68ec98da (diff)
refactor: make Prometheus & Loki config reusable
Diffstat (limited to 'nixos/hosts/tente/grafana.nix')
-rw-r--r--nixos/hosts/tente/grafana.nix63
1 files changed, 63 insertions, 0 deletions
diff --git a/nixos/hosts/tente/grafana.nix b/nixos/hosts/tente/grafana.nix
new file mode 100644
index 0000000..e6fb7af
--- /dev/null
+++ b/nixos/hosts/tente/grafana.nix
@@ -0,0 +1,63 @@
+{ config, lib, pkgs, ... }:
+
+let
+ cfg = config.grafana;
+in
+{
+ options.grafana = {
+ port = lib.mkOption {
+ type = lib.types.int;
+ };
+ matrixForwarderPort = lib.mkOption {
+ type = lib.types.int;
+ };
+ prometheusSqlExporterPort = lib.mkOption {
+ type = lib.types.int;
+ };
+ matrixServerUrl = lib.mkOption {
+ type = lib.types.str;
+ };
+ };
+
+ imports = [
+ <top/shared/prometheus-sql-exporter/service.nix>
+ <top/shared/grafana-matrix-forwarder/service.nix>
+ ];
+
+ config = {
+ age.secrets.grafana-matrix-forwarder-env.file = <top/secrets/grafana-matrix-forwarder-env.age>;
+
+ services.grafana = {
+ enable = true;
+ settings = {
+ server = {
+ http_addr = "0.0.0.0";
+ http_port = cfg.port;
+ };
+ };
+
+ provision = {
+ enable = true;
+ datasources.settings.datasources = [
+ {
+ name = "Prometheus Tente";
+ type = "prometheus";
+ url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}";
+ }
+ {
+ name = "Loki Tente";
+ type = "loki";
+ access = "proxy";
+ url = "http://127.0.0.1:${toString config.services.loki.configuration.server.http_listen_port}";
+ }
+ ];
+ };
+ };
+ services.grafana-matrix-forwarder = {
+ enable = true;
+ port = cfg.matrixForwarderPort;
+ homeserver = cfg.matrixServerUrl;
+ environmentFile = config.age.secrets.grafana-matrix-forwarder-env.path;
+ };
+ };
+}