monitoring: auto-generate Prometheus scrape targets from host configs
Add homelab.monitoring NixOS options (enable, scrapeTargets) following the same pattern as homelab.dns. Prometheus scrape configs are now auto-generated from flake host configurations and external targets, replacing hardcoded target lists. Also cleans up alert rules: snake_case naming, fix zigbee2mqtt typo, remove duplicate pushgateway alert, add for clauses to monitoring_rules, remove hardcoded WireGuard public key, and add new alerts for certificates, proxmox, caddy, smartctl temperature, filesystem prediction, systemd state, file descriptors, and host reboots. Fixes grafana scrape target port from 3100 to 3000. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
{
|
||||
imports = [
|
||||
./dns.nix
|
||||
./monitoring.nix
|
||||
];
|
||||
}
|
||||
|
||||
50
modules/homelab/monitoring.nix
Normal file
50
modules/homelab/monitoring.nix
Normal file
@@ -0,0 +1,50 @@
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
cfg = config.homelab.monitoring;
|
||||
in
|
||||
{
|
||||
options.homelab.monitoring = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Include this host in Prometheus node-exporter scrape targets";
|
||||
};
|
||||
|
||||
scrapeTargets = lib.mkOption {
|
||||
type = lib.types.listOf (lib.types.submodule {
|
||||
options = {
|
||||
job_name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Prometheus scrape job name";
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
description = "Port to scrape metrics from";
|
||||
};
|
||||
metrics_path = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/metrics";
|
||||
description = "HTTP path to scrape metrics from";
|
||||
};
|
||||
scheme = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http";
|
||||
description = "HTTP scheme (http or https)";
|
||||
};
|
||||
scrape_interval = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = "Override the global scrape interval for this target";
|
||||
};
|
||||
honor_labels = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Whether to honor labels from the scraped target";
|
||||
};
|
||||
};
|
||||
});
|
||||
default = [ ];
|
||||
description = "Additional Prometheus scrape targets exposed by this host";
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user