diff --git a/lib/default.nix b/lib/default.nix index 2048027e..aa64cfa7 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -27,7 +27,10 @@ let in { - imports = [ ./users ]; + imports = [ + ./users + ./stats.nix + ]; options.c3d2 = with lib; with lib.types; { @@ -77,8 +80,6 @@ in { ''; }; - statistics = { enable = mkEnableOption "statistics collection"; }; - enableBinaryCache = mkOption { type = bool; default = cfg.isInHq; @@ -241,35 +242,6 @@ in { keyedHosts = filter (x: x != null) list; in listToAttrs keyedHosts; - services.collectd = lib.mkIf cfg.hq.statistics.enable { - enable = true; - extraConfig = '' - FQDNLookup false - Interval 10 - ''; - buildMinimalPackage = true; - plugins = { - logfile = '' - LogLevel info - File STDOUT - ''; - network = '' - Server "grafana.serv.zentralwerk.dn42" "25826" - ''; - memory = ""; - processes = ""; - disk = ""; - df = ""; - cpu = ""; - entropy = ""; - load = ""; - swap = ""; - cgroups = ""; - vmem = ""; - interface = ""; - }; - }; - services.mpd.extraConfig = lib.mkIf cfg.hq.enableMpdProxy '' database { plugin "proxy" diff --git a/lib/stats.nix b/lib/stats.nix new file mode 100644 index 00000000..7d06bf7b --- /dev/null +++ b/lib/stats.nix @@ -0,0 +1,56 @@ +{ lib, config, ... }: + +let + cfg = config.c3d2.hq.statistics; +in +{ + options.c3d2.hq.statistics = { + enable = lib.mkEnableOption "statistics collection"; + }; + + config = { + services.collectd = lib.mkIf cfg.enable { + enable = true; + extraConfig = '' + FQDNLookup false + Interval 10 + ''; + buildMinimalPackage = true; + plugins = { + logfile = '' + LogLevel info + File STDOUT + ''; + network = '' + Server "grafana.serv.zentralwerk.dn42" "25826" + ''; + memory = ""; + processes = ""; + disk = ""; + df = ""; + cpu = ""; + entropy = ""; + load = ""; + swap = ""; + cgroups = ""; + vmem = ""; + interface = ""; + } // lib.optionalAttrs config.services.nginx.enable { + nginx = '' + URL "http://localhost/nginx_status" + ''; + }; + }; + + services.nginx = lib.mkIf config.services.nginx.enable { + virtualHosts.localhost.locations."/nginx_status".extraConfig = '' + stub_status; + + access_log off; + allow 127.0.0.1; + allow ::1; + deny all; + ''; + }; + }; +}