From 51ecc093a05eee41e8421e2cb1cebe20c6c773a6 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Mon, 8 Mar 2021 09:33:42 -0500 Subject: Add monitoring module --- data/aliases.nix | 3 ++ machines/firelink.nix | 1 + modules/monitoring.nix | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 modules/monitoring.nix diff --git a/data/aliases.nix b/data/aliases.nix index 979991a..d179ff3 100644 --- a/data/aliases.nix +++ b/data/aliases.nix @@ -17,5 +17,8 @@ rec { mpd = { address = ip.dragon; port = 11108; }; mpdweb = { address = ip.dragon; port = 11109; }; pjournal = { address = ip.dragon; port = 11110; }; + grafana = { port = 11111; }; + prometheus = { port = 11112; }; + prometheus-exporter = { port = 11113; }; }; } diff --git a/machines/firelink.nix b/machines/firelink.nix index b04c60b..9a17a53 100644 --- a/machines/firelink.nix +++ b/machines/firelink.nix @@ -24,6 +24,7 @@ in { orbekk.gaming.enable = true; orbekk.desktop.enable = true; + orbekk.monitoring.enable = true; environment.systemPackages = with pkgs; [ openmw diff --git a/modules/monitoring.nix b/modules/monitoring.nix new file mode 100644 index 0000000..72adaa9 --- /dev/null +++ b/modules/monitoring.nix @@ -0,0 +1,74 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.orbekk.monitoring; + aliases = import ../data/aliases.nix; +in +{ + options = { + orbekk.monitoring = { + enable = lib.mkEnableOption "Enable monitoring server"; + grafana-port = lib.mkOption { + type = lib.types.int; + default = aliases.services.grafana.port; + }; + grafana-domain = lib.mkOption { + type = lib.types.str; + default = "stats.orbekk.com"; + }; + prometheus-port = lib.mkOption { + type = lib.types.int; + default = aliases.services.prometheus.port; + }; + prometheus-exporter-port = lib.mkOption { + type = lib.types.int; + default = aliases.services.prometheus-exporter.port; + }; + }; + }; + + config = lib.mkIf cfg.enable { + services.grafana = { + enable = true; + domain = cfg.grafana-domain; + port = cfg.grafana-port; + addr = "0.0.0.0"; + + provision = { + enable = true; + datasources = [ + { + name = "Prometheus"; + type = "prometheus"; + access = "proxy"; + orgId = 1; + editable = false; + url = "http://127.0.0.1:${toString cfg.prometheus-port}"; + isDefault = true; + } + ]; + }; + }; + + services.prometheus = { + enable = true; + port = cfg.prometheus-port; + + scrapeConfigs = [ + { + job_name = "self"; + static_configs = [{ + targets = ["127.0.0.1:${toString cfg.prometheus-exporter-port}"]; + }]; + } + ]; + + exporters = { + node = { + enable = true; + enabledCollectors = [ "systemd" ]; + port = cfg.prometheus-exporter-port; + }; + }; + }; + }; +} -- cgit v1.2.3