1 { config, lib, pkgs, ... }:
7 cfg = config.services.statsd;
9 isBuiltinBackend = name:
10 builtins.elem name [ "graphite" "console" "repeater" ];
12 backendsToPackages = let
14 if isBuiltinBackend name then list
15 else list ++ [ pkgs.nodePackages.${name} ];
18 configFile = pkgs.writeText "statsd.conf" ''
20 address: "${cfg.listenAddress}",
21 port: "${toString cfg.port}",
22 mgmt_address: "${cfg.mgmt_address}",
23 mgmt_port: "${toString cfg.mgmt_port}",
25 concatMapStringsSep "," (name:
26 if (isBuiltinBackend name)
27 then ''"./backends/${name}"''
30 ${optionalString (cfg.graphiteHost!=null) ''graphiteHost: "${cfg.graphiteHost}",''}
31 ${optionalString (cfg.graphitePort!=null) ''graphitePort: "${toString cfg.graphitePort}",''}
38 automaticConfigReload: false${optionalString (cfg.extraConfig != null) ","}
43 deps = pkgs.buildEnv {
44 name = "statsd-runtime-deps";
45 pathsToLink = [ "/lib" ];
46 ignoreCollisions = true;
48 paths = backendsToPackages cfg.backends;
57 options.services.statsd = {
59 enable = mkEnableOption "statsd";
61 listenAddress = mkOption {
62 description = "Address that statsd listens on over UDP";
63 default = "127.0.0.1";
68 description = "Port that stats listens for messages on over UDP";
73 mgmt_address = mkOption {
74 description = "Address to run management TCP interface on";
75 default = "127.0.0.1";
79 mgmt_port = mkOption {
80 description = "Port to run the management TCP interface on";
86 description = "List of backends statsd will use for data persistence";
92 "statsd-librato-backend"
93 "stackdriver-statsd-backend"
94 "statsd-influxdb-backend"
96 type = types.listOf types.str;
99 graphiteHost = mkOption {
100 description = "Hostname or IP of Graphite server";
102 type = types.nullOr types.str;
105 graphitePort = mkOption {
106 description = "Port of Graphite server (i.e. carbon-cache).";
108 type = types.nullOr types.int;
111 extraConfig = mkOption {
112 description = "Extra configuration options for statsd";
114 type = types.nullOr types.str;
119 ###### implementation
121 config = mkIf cfg.enable {
123 assertions = map (backend: {
124 assertion = !isBuiltinBackend backend -> hasAttrByPath [ backend ] pkgs.nodePackages;
125 message = "Only builtin backends (graphite, console, repeater) or backends enumerated in `pkgs.nodePackages` are allowed!";
128 users.users.statsd = {
129 uid = config.ids.uids.statsd;
130 description = "Statsd daemon user";
133 systemd.services.statsd = {
134 description = "Statsd Server";
135 wantedBy = [ "multi-user.target" ];
137 NODE_PATH = "${deps}/lib/node_modules";
140 ExecStart = "${pkgs.statsd}/bin/statsd ${configFile}";
145 environment.systemPackages = [ pkgs.statsd ];