2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-08-21 09:43:37 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-08-21 09:43:37 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.statsd;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "statsd.conf" ''
|
|
|
|
{
|
2014-09-11 16:11:16 +00:00
|
|
|
address: "${cfg.host}",
|
2013-08-21 09:43:37 +00:00
|
|
|
port: "${toString cfg.port}",
|
2013-10-12 10:37:52 +00:00
|
|
|
mgmt_address: "${cfg.mgmt_address}",
|
|
|
|
mgmt_port: "${toString cfg.mgmt_port}",
|
2014-09-11 16:11:16 +00:00
|
|
|
backends: [${concatMapStringsSep "," (el: if (nixType el) == "string" then ''"./backends/${el}"'' else ''"${head el.names}"'') cfg.backends}],
|
|
|
|
${optionalString (cfg.graphiteHost!=null) ''graphiteHost: "${cfg.graphiteHost}",''}
|
|
|
|
${optionalString (cfg.graphitePort!=null) ''graphitePort: "${toString cfg.graphitePort}",''}
|
|
|
|
console: {
|
|
|
|
prettyprint: false
|
|
|
|
},
|
|
|
|
log: {
|
|
|
|
backend: "syslog"
|
|
|
|
},
|
|
|
|
automaticConfigReload: false${optionalString (cfg.extraConfig != null) ","}
|
2013-08-21 09:43:37 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.statsd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
description = "Whether to enable statsd stats aggregation service";
|
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
description = "Address that statsd listens on over UDP";
|
|
|
|
default = "127.0.0.1";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-08-21 09:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
description = "Port that stats listens for messages on over UDP";
|
|
|
|
default = 8125;
|
|
|
|
type = types.uniq types.int;
|
|
|
|
};
|
|
|
|
|
2013-10-12 10:37:52 +00:00
|
|
|
mgmt_address = mkOption {
|
2014-12-30 02:31:03 +00:00
|
|
|
description = "Address to run management TCP interface on";
|
2013-10-12 10:37:52 +00:00
|
|
|
default = "127.0.0.1";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-10-12 10:37:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mgmt_port = mkOption {
|
|
|
|
description = "Port to run the management TCP interface on";
|
|
|
|
default = 8126;
|
|
|
|
type = types.uniq types.int;
|
|
|
|
};
|
|
|
|
|
2013-08-21 09:43:37 +00:00
|
|
|
backends = mkOption {
|
2014-12-30 02:31:03 +00:00
|
|
|
description = "List of backends statsd will use for data persistence";
|
2013-08-21 09:43:37 +00:00
|
|
|
default = ["graphite"];
|
2014-09-11 16:11:16 +00:00
|
|
|
example = ["graphite" pkgs.nodePackages."statsd-influxdb-backend"];
|
|
|
|
type = types.listOf (types.either types.str types.package);
|
2013-08-21 09:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
graphiteHost = mkOption {
|
|
|
|
description = "Hostname or IP of Graphite server";
|
2014-09-11 16:11:16 +00:00
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
2013-08-21 09:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
graphitePort = mkOption {
|
2014-06-08 13:59:35 +00:00
|
|
|
description = "Port of Graphite server (i.e. carbon-cache).";
|
2014-09-11 16:11:16 +00:00
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.int;
|
2013-08-21 09:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
description = "Extra configuration options for statsd";
|
2014-09-11 16:11:16 +00:00
|
|
|
default = "";
|
|
|
|
type = types.nullOr types.str;
|
2013-08-21 09:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = "statsd";
|
|
|
|
uid = config.ids.uids.statsd;
|
|
|
|
description = "Statsd daemon user";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.statsd = {
|
|
|
|
description = "Statsd Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2014-09-11 16:11:16 +00:00
|
|
|
environment = {
|
|
|
|
NODE_PATH=concatMapStringsSep ":" (el: "${el}/lib/node_modules") (filter (el: (nixType el) != "string") cfg.backends);
|
|
|
|
};
|
2013-08-21 09:43:37 +00:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.nodePackages.statsd}/bin/statsd ${configFile}";
|
|
|
|
User = "statsd";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [pkgs.nodePackages.statsd];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|