init prometheus module

This commit is contained in:
xinyangli 2023-12-18 10:46:01 +08:00
parent 079ece082a
commit 4e9bf3ebac
2 changed files with 49 additions and 0 deletions

View file

@ -3,5 +3,6 @@
imports = [
./restic.nix
./vaultwarden.nix
./prometheus.nix
];
}

View file

@ -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}" ]; }
];
}
];
};
};
}