From caf9bce3b224ab7e5b2f894aeefbbcea46e85113 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Fri, 7 Apr 2023 22:39:45 +0200 Subject: [PATCH] service/prometheus: init --- modules/services/default.nix | 1 + modules/services/prometheus/default.nix | 88 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 modules/services/prometheus/default.nix diff --git a/modules/services/default.nix b/modules/services/default.nix index 4e065ac..9312f7a 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -20,6 +20,7 @@ ./paperless ./passworts ./photoprism + ./prometheus ./prowlarr ./radarr ./rss-bridge diff --git a/modules/services/prometheus/default.nix b/modules/services/prometheus/default.nix new file mode 100644 index 0000000..d39c9fe --- /dev/null +++ b/modules/services/prometheus/default.nix @@ -0,0 +1,88 @@ +# monitoring system services +{ config, lib, pkgs, ... }: +let + cfg = config.my.services.prometheus; + domain = config.networking.domain; +in +{ + options.my.services.prometheus = with lib; { + enable = mkEnableOption "Prometheus for monitoring"; + + port = mkOption { + type = types.port; + default = 9090; + example = 3002; + description = "Internal port"; + }; + + scrapeInterval = mkOption { + type = types.str; + default = "15s"; + example = "1m"; + description = "Scrape interval"; + }; + + retentionTime = mkOption { + type = types.str; + default = "2y"; + example = "1m"; + description = "retention time"; + }; + }; + + config = lib.mkIf cfg.enable { + services.prometheus = { + enable = true; + inherit (cfg) port; + listenAddress = "127.0.0.1"; + + inherit (cfg) retentionTime; + + exporters = { + node = { + enable = true; + enabledCollectors = [ "systemd" ]; + port = 9100; + listenAddress = "127.0.0.1"; + }; + }; + + globalConfig = { + scrape_interval = cfg.scrapeInterval; + }; + + scrapeConfigs = [ + { + job_name = config.networking.hostName; + static_configs = [{ + targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.node.port}" ]; + }]; + } + ]; + }; + + services.grafana.provision.dashboards.settings.providers = [ + { + name = "Node Exporter"; + options.path = pkgs.node-exporter-dashboard; + disableDeletion = true; + } + ]; + + my.services.nginx.virtualHosts = [ + { + subdomain = "monitoring"; + inherit (cfg) port; + } + ]; + + webapps.apps.prometheus = { + dashboard = { + name = "Monitoring"; + category = "infra"; + icon = "heart-pulse"; + link = "https://monitoring.${domain}"; + }; + }; + }; +}