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 --- modules/monitoring.nix | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 modules/monitoring.nix (limited to 'modules') 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