diff options
author | Maximilian Bosch <maximilian@mbosch.me> | 2017-11-25 23:54:37 +0100 |
---|---|---|
committer | Rok Garbas <rok@garbas.si> | 2017-12-04 16:56:16 +0100 |
commit | aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1 (patch) | |
tree | edc107c520548f620a0f12dccbb5350296166397 /nixos/modules | |
parent | 67a86f78139f9ab3bf83c0069db12a11e5a47393 (diff) | |
download | nixlib-aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1.tar nixlib-aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1.tar.gz nixlib-aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1.tar.bz2 nixlib-aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1.tar.lz nixlib-aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1.tar.xz nixlib-aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1.tar.zst nixlib-aaf1e1c4fb6e42d4b37928ba4d98cfbf1a67e8f1.zip |
statsd: restore support for {influx,librato,stackdriver} backends
These packages will be placed into an environment using `backendsToPackages`. This function explicitly maps backends to `pkgs.nodePackages.${type}` unless it's a builtin. This ensures that only valid backends that work on NixOS are used (if not, the build already breaks at evaluation time). The log will be redirected to `stdout` to be able to watch the entire output using `journalctl`. Configuration parameters for the backends need to be set using `services.statsd.extraConfig` as each backend has its own options and all of them shouldn't be validated and checked explicitly and manually.
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/services/monitoring/statsd.nix | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/nixos/modules/services/monitoring/statsd.nix b/nixos/modules/services/monitoring/statsd.nix index df2adb9f2766..7b0e9981cbb1 100644 --- a/nixos/modules/services/monitoring/statsd.nix +++ b/nixos/modules/services/monitoring/statsd.nix @@ -9,6 +9,12 @@ let isBuiltinBackend = name: builtins.elem name [ "graphite" "console" "repeater" ]; + backendsToPackages = let + mkMap = list: name: + if isBuiltinBackend name then list + else list ++ [ pkgs.nodePackages.${name} ]; + in foldl mkMap []; + configFile = pkgs.writeText "statsd.conf" '' { address: "${cfg.listenAddress}", @@ -27,13 +33,21 @@ let prettyprint: false }, log: { - backend: "syslog" + backend: "stdout" }, automaticConfigReload: false${optionalString (cfg.extraConfig != null) ","} ${cfg.extraConfig} } ''; + deps = pkgs.buildEnv { + name = "statsd-runtime-deps"; + pathsToLink = [ "/lib" ]; + ignoreCollisions = true; + + paths = backendsToPackages cfg.backends; + }; + in { @@ -42,11 +56,7 @@ in options.services.statsd = { - enable = mkOption { - description = "Whether to enable statsd stats aggregation service"; - default = false; - type = types.bool; - }; + enable = mkEnableOption "statsd"; listenAddress = mkOption { description = "Address that statsd listens on over UDP"; @@ -110,6 +120,11 @@ in config = mkIf cfg.enable { + assertions = map (backend: { + assertion = !isBuiltinBackend backend -> hasAttrByPath [ backend ] pkgs.nodePackages; + message = "Only builtin backends (graphite, console, repeater) or backends enumerated in `pkgs.nodePackages` are allowed!"; + }) cfg.backends; + users.extraUsers = singleton { name = "statsd"; uid = config.ids.uids.statsd; @@ -120,9 +135,7 @@ in description = "Statsd Server"; wantedBy = [ "multi-user.target" ]; environment = { - NODE_PATH=concatMapStringsSep ":" - (pkg: "${builtins.getAttr pkg pkgs.statsd.nodePackages}/lib/node_modules") - (filter (name: !isBuiltinBackend name) cfg.backends); + NODE_PATH = "${deps}/lib/node_modules"; }; serviceConfig = { ExecStart = "${pkgs.statsd}/bin/statsd ${configFile}"; |