nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

commit a936f9432e935a1ef69f87cad21278bd2825f8ef
parent 3d2934397a730133d53651a970ef829b80b914ad
Author: mtmn <miro@haravara.org>
Date:   Mon, 15 Jun 2026 23:54:15 +0200

nix: add blackbox-exporter and mounts

Diffstat:
Mhosts/nixaran/configuration.nix | 0
Mmodules/services/monitoring/default.nix | 27+++++++++++++++++++++++++++
Mmodules/services/monitoring/exporters.nix | 50+++++++++++++++++++++++++++++++++++++++++++++++---
Mmodules/services/monitoring/grafana.nix | 5+++++
4 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/hosts/nixaran/configuration.nix b/hosts/nixaran/configuration.nix Binary files differ. diff --git a/modules/services/monitoring/default.nix b/modules/services/monitoring/default.nix @@ -145,6 +145,33 @@ in { job_name = "alertmanager"; static_configs = [{targets = ["127.0.0.1:${toString cfg.alertmanager.port}"];}]; } + ++ lib.optional cfg.exporters.blackbox.enable { + job_name = "blackbox_exporter"; + metrics_path = "/probe"; + static_configs = + lib.optional (cfg.exporters.blackbox.http_targets != []) { + targets = cfg.exporters.blackbox.http_targets; + labels.__param_module = "http"; + } + ++ lib.optional (cfg.exporters.blackbox.tcp_targets != []) { + targets = cfg.exporters.blackbox.tcp_targets; + labels.__param_module = "tcp_connect"; + }; + relabel_configs = [ + { + source_labels = ["__address__"]; + target_label = "__param_target"; + } + { + source_labels = ["__param_target"]; + target_label = "instance"; + } + { + target_label = "__address__"; + replacement = "127.0.0.1:${toString cfg.exporters.blackbox.port}"; + } + ]; + } ++ cfg.victoriametrics.extraScrapeConfigs; }; }; diff --git a/modules/services/monitoring/exporters.nix b/modules/services/monitoring/exporters.nix @@ -1,6 +1,7 @@ { config, lib, + pkgs, ... }: let cfg = config.services.haravara.monitoring; @@ -12,18 +13,52 @@ in { default = []; description = "Additional static_configs appended to the node_exporter job"; }; + blackbox = { + enable = lib.mkEnableOption "Blackbox Prometheus exporter for endpoint probing"; + port = lib.mkOption { + type = lib.types.port; + default = 9115; + description = "Port for the blackbox exporter to listen on"; + }; + modules = lib.mkOption { + type = lib.types.attrs; + default = { + http = { + prober = "http"; + timeout = "5s"; + http = { + fail_if_not_ssl = true; + valid_status_codes = [200 301 302 401 403 404]; + }; + }; + tcp_connect = { + prober = "tcp"; + timeout = "5s"; + }; + }; + description = "Blackbox exporter probe modules"; + }; + http_targets = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = []; + }; + tcp_targets = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = []; + }; + }; }; config = lib.mkIf (cfg.enable && cfg.exporters.enable) { - services.prometheus = { - exporters.node = { + services.prometheus.exporters = { + node = { enable = true; listenAddress = "127.0.0.1"; enabledCollectors = ["systemd"]; port = 9100; }; - exporters.systemd = { + systemd = { enable = true; listenAddress = "127.0.0.1"; port = 9558; @@ -31,6 +66,15 @@ in { "--systemd.collector.unit-exclude=.*\\\\.(mount|slice|scope|target|device|path|timer|automount|socket|swap)" ]; }; + + blackbox = lib.mkIf cfg.exporters.blackbox.enable { + enable = true; + listenAddress = "127.0.0.1"; + port = cfg.exporters.blackbox.port; + configFile = (pkgs.formats.yaml {}).generate "blackbox.yml" { + modules = cfg.exporters.blackbox.modules; + }; + }; }; systemd.services = { diff --git a/modules/services/monitoring/grafana.nix b/modules/services/monitoring/grafana.nix @@ -84,6 +84,11 @@ name = "corpus.json"; url = "https://raw.githubusercontent.com/mtmn/corpus/master/monitoring/grafana-dashboard.json"; sha256 = "0b6d4kvcwarv1isy3i4x0l4an7b3zyxyy9af3acr9gbfkkrbyjv5"; + }) + ++ lib.optional config.services.haravara.monitoring.exporters.blackbox.enable (fetchDashboard { + name = "blackbox_exporter.json"; + url = "https://grafana.com/api/dashboards/14928/revisions/6/download"; + sha256 = "4643193a1d77ba6c7e8d57e13d517531e2e7a6358cd0d1c832f9999229529286"; })); in { options.services.haravara.monitoring.grafana = {