From 862e8ecfb2eea13d9d79a9c3f00a0873373fec02 Mon Sep 17 00:00:00 2001 From: Rouven Seifert Date: Sun, 29 Oct 2023 11:58:56 +0100 Subject: [PATCH] add grafana and prometheus --- flake.lock | 15 ++++---- flake.nix | 3 +- hosts/nuc/default.nix | 3 +- hosts/nuc/modules/backup/default.nix | 11 +++--- hosts/nuc/modules/grafana/default.nix | 44 +++++++++++++++++++++++ hosts/nuc/modules/prometheus/default.nix | 35 ++++++++++++++++++ hosts/nuc/modules/uptime-kuma/default.nix | 2 +- hosts/thinkpad/modules/backup/default.nix | 1 - 8 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 hosts/nuc/modules/grafana/default.nix create mode 100644 hosts/nuc/modules/prometheus/default.nix diff --git a/flake.lock b/flake.lock index 32c9a1f..b1cedb7 100644 --- a/flake.lock +++ b/flake.lock @@ -301,18 +301,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1698463958, - "narHash": "sha256-4L0hGqplwNYWFhqhPbsQh6U7s4KiUSE2nhQdCZg981c=", - "owner": "imlonghao", + "lastModified": 1698318101, + "narHash": "sha256-gUihHt3yPD7bVqg+k/UVHgngyaJ3DMEBchbymBMvK1E=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "88bc98a073d12dc7e0c8b766a55d39ebeaed9927", + "rev": "63678e9f3d3afecfeafa0acead6239cdb447574c", "type": "github" }, "original": { - "owner": "imlonghao", - "ref": "borgmatic/fix-262020", - "repo": "nixpkgs", - "type": "github" + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" } }, "nixpkgs-lib": { diff --git a/flake.nix b/flake.nix index 5c26a86..2d978ae 100644 --- a/flake.nix +++ b/flake.nix @@ -2,8 +2,7 @@ description = "My nix setup"; inputs = { - # nixpkgs.url = "nixpkgs/nixos-unstable"; - nixpkgs.url = "github:imlonghao/nixpkgs/borgmatic/fix-262020"; + nixpkgs.url = "nixpkgs/nixos-unstable"; nix-index-database = { url = "github:nix-community/nix-index-database"; diff --git a/hosts/nuc/default.nix b/hosts/nuc/default.nix index d4a4a96..f72e972 100644 --- a/hosts/nuc/default.nix +++ b/hosts/nuc/default.nix @@ -7,7 +7,8 @@ # ./modules/adguard ./modules/networks # ./modules/backup - # ./modules/hydra + ./modules/grafana + ./modules/prometheus ./modules/matrix ./modules/nextcloud ./modules/seafile diff --git a/hosts/nuc/modules/backup/default.nix b/hosts/nuc/modules/backup/default.nix index 881672f..3aa4745 100644 --- a/hosts/nuc/modules/backup/default.nix +++ b/hosts/nuc/modules/backup/default.nix @@ -25,13 +25,10 @@ ]; encryption_passcommand = "${pkgs.coreutils}/bin/cat ${config.sops.secrets."borg/passphrase".path}"; compression = "lz4"; - retention = { - keep_daily = 7; - keep_weekly = 4; - keep_monthly = 12; - keep_yearly = 3; - - }; + keep_daily = 7; + keep_weekly = 4; + keep_monthly = 12; + keep_yearly = 3; }; }; } diff --git a/hosts/nuc/modules/grafana/default.nix b/hosts/nuc/modules/grafana/default.nix new file mode 100644 index 0000000..c7ded09 --- /dev/null +++ b/hosts/nuc/modules/grafana/default.nix @@ -0,0 +1,44 @@ +{ config, ... }: +let + domain = "monitoring.${config.networking.domain}"; +in +{ + services.grafana = { + enable = true; + settings = { + server = { + inherit domain; + http_addr = "127.0.0.1"; + http_port = 3000; + }; + database = { + type = "postgres"; + user = "grafana"; + host = "/run/postgresql"; + }; + }; + }; + + + services.postgresql = { + enable = true; + ensureUsers = [ + { + name = "grafana"; + ensurePermissions = { + "DATABASE grafana" = "ALL PRIVILEGES"; + }; + } + ]; + ensureDatabases = [ "grafana" ]; + }; + + services.nginx.virtualHosts."${domain}" = { + addSSL = true; + enableACME = true; + locations."/" = { + proxyPass = "http://${toString config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}/"; + proxyWebsockets = true; + }; + }; +} diff --git a/hosts/nuc/modules/prometheus/default.nix b/hosts/nuc/modules/prometheus/default.nix new file mode 100644 index 0000000..2b068b7 --- /dev/null +++ b/hosts/nuc/modules/prometheus/default.nix @@ -0,0 +1,35 @@ +{ config, ... }: +let + exportersConfig = config.services.prometheus.exporters; +in +{ + services.prometheus = { + enable = true; + exporters = { + node = { + enable = true; + enabledCollectors = [ "systemd" ]; + }; + postgres.enable = true; + }; + scrapeConfigs = [ + { + job_name = "node"; + static_configs = [ + { + targets = [ "127.0.0.1:${toString exportersConfig.node.port}" ]; + } + ]; + } + { + job_name = "postgres"; + static_configs = [ + { + targets = [ "127.0.0.1:${toString exportersConfig.postgres.port}" ]; + } + ]; + } + ]; + + }; +} diff --git a/hosts/nuc/modules/uptime-kuma/default.nix b/hosts/nuc/modules/uptime-kuma/default.nix index 27f61fa..9d2e32b 100644 --- a/hosts/nuc/modules/uptime-kuma/default.nix +++ b/hosts/nuc/modules/uptime-kuma/default.nix @@ -1,6 +1,6 @@ { config, ... }: let - domain = "monitoring.${config.networking.domain}"; + domain = "uptime.${config.networking.domain}"; in { services.uptime-kuma = { diff --git a/hosts/thinkpad/modules/backup/default.nix b/hosts/thinkpad/modules/backup/default.nix index 617fe3f..c7270b7 100644 --- a/hosts/thinkpad/modules/backup/default.nix +++ b/hosts/thinkpad/modules/backup/default.nix @@ -5,7 +5,6 @@ services.borgmatic = { enable = true; settings = { - location = { }; source_directories = [ "/var/lib" "/var/log"