From 4e9bf3ebacd76541a69595d3f9792d8981760b53 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Mon, 18 Dec 2023 10:46:01 +0800 Subject: [PATCH] init prometheus module --- modules/nixos/default.nix | 1 + modules/nixos/prometheus.nix | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 modules/nixos/prometheus.nix 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