From 97916aaa055f05e5af6b640c374ff4ae1f90c1e0 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sun, 8 Oct 2023 03:28:35 +0800 Subject: [PATCH] hosts/plover: init Prometheus monitoring daemon --- hosts/plover/default.nix | 1 + hosts/plover/modules/services/prometheus.nix | 43 ++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 hosts/plover/modules/services/prometheus.nix diff --git a/hosts/plover/default.nix b/hosts/plover/default.nix index 25d6ea28..eea959c6 100644 --- a/hosts/plover/default.nix +++ b/hosts/plover/default.nix @@ -33,6 +33,7 @@ in ./modules/services/vouch-proxy.nix # The monitoring stack. + ./modules/services/prometheus.nix ./modules/services/grafana.nix # The database of choice which is used by most self-managed services on diff --git a/hosts/plover/modules/services/prometheus.nix b/hosts/plover/modules/services/prometheus.nix new file mode 100644 index 00000000..fbae26c1 --- /dev/null +++ b/hosts/plover/modules/services/prometheus.nix @@ -0,0 +1,43 @@ +{ config, lib, pkgs, ... }: + +let + bindStatsPort = 8053; + prometheusExports = config.services.prometheus.exporters; +in +{ + services.prometheus = { + enable = true; + + exporters = { + bind = { + enable = true; + bindURI = "http://127.0.0.1/${builtins.toString bindStatsPort}"; + }; + + nginx.enable = true; + nginxlog.enable = true; + + node = { + enable = true; + enabledCollectors = [ "systemd" ]; + }; + }; + + scrapeConfigs = [ + { + job_name = config.networking.hostName; + static_configs = [{ + targets = [ "127.0.0.1:${builtins.toString prometheusExports.node.port}" ]; + }]; + } + ]; + }; + + # Requiring this for Prometheus being able to monitor my services. + services.nginx.statusPage = true; + services.bind.extraConfig = '' + statistics-channels { + inet 127.0.0.1 port ${builtins.toString bindStatsPort} allow { 127.0.0.1; }; + }; + ''; +}