From 7526b9273bd167c5d1ed40abdc84336172399eea Mon Sep 17 00:00:00 2001 From: quitte Date: Mon, 29 Apr 2024 15:09:56 +0200 Subject: [PATCH] making grafana work --- flake.nix | 1 + modules/monitoring.nix | 64 ++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index 827b6d0..6159bc2 100755 --- a/flake.nix +++ b/flake.nix @@ -83,6 +83,7 @@ ./modules/hedgedoc.nix ./modules/padlist.nix ./modules/nextcloud.nix + ./modules/monitoring.nix ./modules/vaultwarden.nix ./modules/forgejo ./modules/kanboard.nix diff --git a/modules/monitoring.nix b/modules/monitoring.nix index d3cdb3e..ff8dc58 100644 --- a/modules/monitoring.nix +++ b/modules/monitoring.nix @@ -1,23 +1,51 @@ { config, pkgs, ... }: - let - domain = "monitoring.${config.networking.domain}"; - in { - # grafana configuration - services.grafana = { - enable = true; - port = 2342; - }; - - services.prometheus = { - enable = true; - port = 9001; +let + domain = "monitoring.${config.networking.domain}"; +in +{ + # grafana configuration + services.grafana = { + enable = true; + settings = { + server = { + inherit domain; + http_addr = "127.0.0.1"; + http_port = 2342; + }; + database = { + type = "postgres"; + user = "grafana"; + host = "/run/postgresql"; + }; + }; - # nginx reverse proxy - services.nginx.virtualHosts.${domain} = { - locations."/" = { - proxyPass = "http://localhost:${toString config.services.grafana.port}"; - proxyWebsockets = true; - }; + + }; + + services.postgresql = { + enable = true; + ensureUsers = [ + { + name = "grafana"; + ensurePermissions = { + "DATABASE grafana" = "ALL PRIVILEGES"; + }; + } + ]; + ensureDatabases = [ "grafana" ]; + }; + + services.prometheus = { + enable = true; + port = 9001; + }; + + # nginx reverse proxy + services.nginx.virtualHosts.${domain} = { + locations."/" = { + proxyPass = "http://localhost:${toString config.services.grafana.port}"; + proxyWebsockets = true; }; + }; }