diff options
Diffstat (limited to 'modules/by-name/mo/monitoring/components')
| -rw-r--r-- | modules/by-name/mo/monitoring/components/grafana.nix | 12 | ||||
| -rw-r--r-- | modules/by-name/mo/monitoring/components/loki.nix | 84 | ||||
| -rw-r--r-- | modules/by-name/mo/monitoring/components/prometheus.nix | 78 |
3 files changed, 122 insertions, 52 deletions
diff --git a/modules/by-name/mo/monitoring/components/grafana.nix b/modules/by-name/mo/monitoring/components/grafana.nix index 7b9665a..6fe5b70 100644 --- a/modules/by-name/mo/monitoring/components/grafana.nix +++ b/modules/by-name/mo/monitoring/components/grafana.nix @@ -146,13 +146,15 @@ in { ]; monitoring.grafana.dashboards = [ - ../dashboards/Errors.json - ../dashboards/Performance.json - ../dashboards/Scraping_Jobs.json + ../dashboards/node_exporter.json + ../dashboards/performance.json + ../dashboards/scraping_jobs.json + ../dashboards/systemd_exporter.json ]; + + anubis.instances."${cfg.fqdn}".target = "http://${config.services.grafana.settings.server.http_addr}:${toString cfg.port}"; }; - vhack.anubis.instances."${cfg.fqdn}".target = "http://${config.services.grafana.settings.server.http_addr}:${toString cfg.port}"; services = { postgresql = { ensureUsers = [ @@ -209,7 +211,7 @@ in { folder = "Vhack"; options.path = pkgs.symlinkJoin { name = "dashboards"; - paths = map (p: pkgs.runCommand "davhackoard" {} "mkdir $out; cp ${p} $out") cfg.dashboards; + paths = map (p: pkgs.runCommand "dashoard" {} "mkdir $out; cp ${p} $out") cfg.dashboards; }; allowUiUpdates = true; disableDeletion = true; diff --git a/modules/by-name/mo/monitoring/components/loki.nix b/modules/by-name/mo/monitoring/components/loki.nix index ac9b1fa..149e577 100644 --- a/modules/by-name/mo/monitoring/components/loki.nix +++ b/modules/by-name/mo/monitoring/components/loki.nix @@ -67,48 +67,6 @@ in { }; }; services = { - loki = { - enable = true; - dataDir = "/var/lib/loki"; - package = pkgs.grafana-loki; - configuration = { - auth_enabled = false; - - server.http_listen_port = cfg.port; - - common = { - ring = { - instance_addr = "127.0.0.1"; - kvstore = { - store = "inmemory"; - }; - }; - - replication_factor = 1; - path_prefix = "/tmp/loki"; - }; - - schema_config = { - configs = [ - { - from = "2020-05-15"; - store = "tsdb"; - object_store = "filesystem"; - schema = "v13"; - index = { - prefix = "index_"; - period = "24h"; - }; - } - ]; - }; - - storage_config = { - filesystem.directory = "/tmp/loki/chunks"; - }; - }; - }; - fluent-bit = { enable = true; settings = { @@ -165,6 +123,48 @@ in { }; graceLimit = "1m"; }; + + loki = { + enable = true; + dataDir = "/var/lib/loki"; + package = pkgs.grafana-loki; + configuration = { + auth_enabled = false; + + server.http_listen_port = cfg.port; + + common = { + ring = { + instance_addr = "127.0.0.1"; + kvstore = { + store = "inmemory"; + }; + }; + + replication_factor = 1; + path_prefix = "/tmp/loki"; + }; + + schema_config = { + configs = [ + { + from = "2020-05-15"; + store = "tsdb"; + object_store = "filesystem"; + schema = "v13"; + index = { + prefix = "index_"; + period = "24h"; + }; + } + ]; + }; + + storage_config = { + filesystem.directory = "/tmp/loki/chunks"; + }; + }; + }; }; }; } diff --git a/modules/by-name/mo/monitoring/components/prometheus.nix b/modules/by-name/mo/monitoring/components/prometheus.nix index dbe6c06..ca947d3 100644 --- a/modules/by-name/mo/monitoring/components/prometheus.nix +++ b/modules/by-name/mo/monitoring/components/prometheus.nix @@ -8,7 +8,6 @@ commonLabels = { hostname = config.networking.hostName; - inherit (config.vhack.monitoring.grafana) fqdn; }; prom_cfg = config.services.prometheus; @@ -22,6 +21,35 @@ in { default = 3001; }; + remoteWriteReceiver = lib.mkOption { + example = "https://prometheus.server2.vhack.eu"; + type = lib.types.nullOr lib.types.str; + default = null; + description = '' + If not null, this prometheus server will be exposed via a reverse proxy and allow + other prometheus servers to write metrics to it. + ''; + }; + remoteWriteTo = lib.mkOption { + example = "https://prometheus.server3.vhack.eu"; + type = lib.types.nullOr (lib.types.submodule { + options = { + port = lib.mkOption { + type = lib.types.nullOr lib.types.port; + default = null; + }; + url = lib.mkOption { + type = lib.types.str; + }; + }; + }); + default = null; + description = '' + If not null, this prometheus server will run in agent mode, writing all recived + metrics to the specified remote prometheus server. + ''; + }; + sources = lib.mkOption { type = lib.types.listOf (lib.types.submodule { options = { @@ -30,6 +58,7 @@ in { }; target = lib.mkOption { type = lib.types.str; + description = "The target url to scrape from."; }; extra = lib.mkOption { type = lib.types.attrsOf lib.types.anything; @@ -68,6 +97,20 @@ in { ]; }; + services.nginx = lib.mkIf (cfg.remoteWriteReceiver != null) { + virtualHosts.${cfg.remoteWriteReceiver} = { + locations."/" = { + proxyPass = "http://127.0.0.1:${toString cfg.port}/api/v1/write"; + + recommendedProxySettings = true; + proxyWebsockets = true; + }; + + enableACME = true; + forceSSL = true; + }; + }; + users = { groups = { node-exporter.gid = config.vhack.constants.ids.gids.node-exporter; @@ -89,6 +132,28 @@ in { globalConfig = { scrape_interval = "15s"; }; + remoteWrite = lib.optionals (cfg.remoteWriteTo != null) [ + { + url = let + port = + if (cfg.remoteWriteTo.port != null) + then ":${toString cfg.remoteWriteTo.port}" + else ""; + in "${cfg.remoteWriteTo.url}${port}"; + # TODO: Needs RFC42 for prometheus <2026-07-19> + # protobuf_message = "io.prometheus.write.v2.Request"; + } + ]; + + enableAgentMode = cfg.remoteWriteTo != null; + extraFlags = lib.mkMerge [ + ( + lib.mkIf (cfg.remoteWriteReceiver != null) [ + "--web.enable-remote-write-receiver" + # "--web.remote-write-receiver.accepted-protobuf-messages=io.prometheus.write.v2.Request" + ] + ) + ]; scrapeConfigs = builtins.map (attr: nixLib.warnMerge { @@ -100,7 +165,7 @@ in { } ]; } - attr.extra "prometheus scrapeConfig") + attr.extra "prometheus scrapeConfig '${attr.name}'") cfg.sources; # ++ (lib.optional (builtins.length (lib.attrNames config.services.redis.servers) > 0) { # job_name = "redis"; @@ -190,11 +255,14 @@ in { port = 9116; listenAddress = "127.0.0.1"; extraFlags = [ + "--log.level=info" + "--web.disable-exporter-metrics" + # "--systemd.collector.enable-resolved" "--systemd.collector.enable-restart-count" - "--systemd.collector.enable-file-descriptor-size" + # "--systemd.collector.enable-file-descriptor-size" "--systemd.collector.enable-ip-accounting" - "--log.level=info" - "--systemd.collector.unit-include=.*.service|.*.timer" + "--systemd.collector.unit-include=\".+\"" + "--systemd.collector.unit-exclude=\".+\\\\.(device)\"" ]; }; }; |
