From 5c3b9fd7910e5eb1e6dcca519f440a0bb4b2aa09 Mon Sep 17 00:00:00 2001 From: Hendrik Sokolowski Date: Sun, 1 Oct 2023 22:45:21 +0200 Subject: [PATCH] Extend monitoring-server --- modules/monitoring-server/default.nix | 100 ++++++++++++++++++++------ 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/modules/monitoring-server/default.nix b/modules/monitoring-server/default.nix index 22070d6e..eb225181 100644 --- a/modules/monitoring-server/default.nix +++ b/modules/monitoring-server/default.nix @@ -10,60 +10,120 @@ with lib; let in { options.pub-solar.monitoring-server = { enable = mkEnableOption "Install a monitoring server node"; + listenAddress = mkOption { + type = types.str; + default = "127.0.0.1"; + }; + grafana = { + enable = mkEnableOption "Run grafana"; + port = mkOption { + type = types.int; + default = 2342; + }; + }; + node_exporter = { + enable = mkEnableOption "prometheus node-exporter support"; + hosts = mkOption { + type = types.listOf types.str; + }; + }; + snmp = { + enable = mkEnableOption "prometheus snmp export support"; + hosts = mkOption { + #type = types.Or (types.AttrSet types.listOf types.str); + }; + settings = mkOption { + type = types.NullOr types.AttrSet; + default = null; + }; + }; + smokeping = { + enable = mkEnableOption "prometheus smokeping support"; + hosts = mkOption { + type = types.listOf types.str; + }; + }; }; config = mkIf cfg.enable { - networking.firewall.allowedTCPPorts = [2342 9001]; + networking.firewall.allowedTCPPorts = [cfg.grafana.port 9001 9374]; pub-solar.monitoring-client = { enable = true; - listenAddress = "10.0.1.6"; + listenAddress = cfg.listenAddress; }; - services.grafana = { + services.grafana = mkIf cfg.grafana.enable { enable = true; - port = 2342; - addr = "10.0.1.6"; + settings = { + server = { + http_addr = cfg.listenAddress; + http_port = cfg.grafana.port; + }; + }; }; services.prometheus = { enable = true; - listenAddress = "10.0.1.6"; + listenAddress = cfg.listenAddress; port = 9001; scrapeConfigs = [ { - job_name = "chonk"; + job_name = "node_exporters"; static_configs = [ { - targets = ["10.0.1.6:9002"]; + targets = + ["${cfg.listenAddress}:9002"] + ++ cfg.node_exporter.hosts; } ]; } { - job_name = "giggles"; + job_name = "snmp_wohnung_aachen_mikrotik"; + scrape_interval = "15s"; static_configs = [ { - targets = ["10.0.1.11:9002"]; + targets = cfg.snmp.hosts; + } + ]; + metrics_path = "/snmp"; + params = { + auth = ["public_v2"]; + module = ["if_mib"]; + }; + relabel_configs = [ + { + source_labels = ["__address__"]; + target_label = "__param_target"; + } + { + source_labels = ["__param_target"]; + target_label = "instance"; + } + { + target_label = "__address__"; + replacement = "10.0.1.254:9116"; } ]; } { - job_name = "cox"; + job_name = "smokeping"; + scrape_interval = "15s"; static_configs = [ { - targets = ["10.0.1.12:9002"]; - } - ]; - } - { - job_name = "companion"; - static_configs = [ - { - targets = ["10.0.1.13:9002"]; + targets = [ + "${cfg.listenAddress}:9374" + ]; } ]; } ]; + + exporters.smokeping = mkIf cfg.smokeping.enable { + enable = true; + listenAddress = cfg.listenAddress; + hosts = cfg.smokeping.hosts; + }; }; }; }