{ config, lib, pkgs, ... }: with lib; let cfg = config.nixfiles.modules.monitoring; in { options.nixfiles.modules.monitoring.enable = mkEnableOption "custom monitoring stack"; config = mkIf cfg.enable { nixfiles.modules = { grafana.enable = true; loki.enable = true; prometheus.enable = true; alertmanager.enable = true; }; services = { grafana.provision = { enable = true; datasources = with config.nixfiles.modules; [ { name = "Prometheus"; type = "prometheus"; access = "proxy"; url = "https://${prometheus.domain}"; isDefault = true; } { name = "Loki"; type = "loki"; access = "proxy"; url = "https://${loki.domain}"; } ]; # TODO Move dashboards to this repository. dashboards = [ { name = "system"; options.path = pkgs.fetchurl { url = "https://gist.githubusercontent.com/azahi/b8951223e6850d88159b0c34749a20aa/raw/00c6928374b5d231dc3afe617165550868b8c233/System-1645616603173.json"; sha256 = "sha256-vGlCOHT5Rp1K88Z8lkLGkvTDeFpgi967CSOb/797vwY="; }; } { name = "endlessh-go"; options.path = pkgs.fetchurl { url = "https://gist.githubusercontent.com/azahi/fd917e917fb53deacf3c6d7366bae2b2/raw/796530bd899e9328e423d18a462faf3c7d01c823/endlessh.json"; sha256 = "sha256-/wJDiFlrHEa1f82pDFtG/T2GRKGlAur0dlQ8eeVJ3m4="; }; } { name = "unbound"; options.path = ./dashboards/unbound.json; } { name = "nginx"; options.path = ./dashboards/nginx.json; } { name = "postgersql"; options.path = ./dashboards/postgresql.json; } ]; }; loki.configuration.ruler.alertmanager_url = "https://${config.nixfiles.modules.alertmanager.domain}"; prometheus.alertmanagers = [ { scheme = "https"; static_configs = [{targets = [config.nixfiles.modules.alertmanager.domain];}]; } ]; }; }; }