diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index 1b91ad5..e89ad69 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -3,5 +3,6 @@ imports = [ ./restic.nix ./vaultwarden.nix + ./prometheus.nix ]; } \ No newline at end of file diff --git a/modules/nixos/prometheus.nix b/modules/nixos/prometheus.nix new file mode 100644 index 0000000..ac0a976 --- /dev/null +++ b/modules/nixos/prometheus.nix @@ -0,0 +1,48 @@ + +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.custom.prometheus; +in +{ + options = { + custom.prometheus = { + enable = mkEnableOption "Prometheus instance"; + exporters = { + enable = mkOption { + type = types.bool; + default = false; + description = "Enable Prometheus exporter on every supported services"; + }; + }; + }; + }; + + config = { + services.prometheus = mkIf cfg.enable { + enable = true; + port = 9091; + exporters = { + node = { + enable = true; + enabledCollectors = [ "systemd" ]; + port = 9100; + }; + }; + scrapeConfigs = [ + { job_name = "prometheus"; + static_configs = [ + { targets = [ "localhost:${toString config.services.prometheus.port}" ]; } + ]; + } + { job_name = "node"; + static_configs = [ + { targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; } + ]; + } + ]; + }; + }; +} \ No newline at end of file