2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-08-21 11:43:37 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-08-21 11:43:37 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.statsd;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "statsd.conf" ''
|
|
|
|
{
|
|
|
|
host: "${cfg.host}",
|
|
|
|
port: "${toString cfg.port}",
|
2013-10-12 12:37:52 +02:00
|
|
|
mgmt_address: "${cfg.mgmt_address}",
|
|
|
|
mgmt_port: "${toString cfg.mgmt_port}",
|
2013-08-21 11:43:37 +02:00
|
|
|
backends: [${concatMapStrings (el: ''"./backends/${el}",'') cfg.backends}],
|
|
|
|
graphiteHost: "${cfg.graphiteHost}",
|
|
|
|
graphitePort: "${toString cfg.graphitePort}",
|
|
|
|
${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 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-21 11:43:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
description = "Port that stats listens for messages on over UDP";
|
|
|
|
default = 8125;
|
|
|
|
type = types.uniq types.int;
|
|
|
|
};
|
|
|
|
|
2013-10-12 12:37:52 +02:00
|
|
|
mgmt_address = mkOption {
|
|
|
|
description = "Address to run managment TCP interface on";
|
|
|
|
default = "127.0.0.1";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-10-12 12:37:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
mgmt_port = mkOption {
|
|
|
|
description = "Port to run the management TCP interface on";
|
|
|
|
default = 8126;
|
|
|
|
type = types.uniq types.int;
|
|
|
|
};
|
|
|
|
|
2013-08-21 11:43:37 +02:00
|
|
|
backends = mkOption {
|
|
|
|
description = "List of backends statsd will use for data persistance";
|
|
|
|
default = ["graphite"];
|
|
|
|
};
|
|
|
|
|
|
|
|
graphiteHost = mkOption {
|
|
|
|
description = "Hostname or IP of Graphite server";
|
2014-03-10 11:01:38 +01:00
|
|
|
default = config.services.graphite.web.host;
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-21 11:43:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
graphitePort = mkOption {
|
2014-06-08 15:59:35 +02:00
|
|
|
description = "Port of Graphite server (i.e. carbon-cache).";
|
|
|
|
default = 2003;
|
2013-08-21 11:43:37 +02:00
|
|
|
type = types.uniq types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Extra configuration options for statsd";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-21 11:43:37 +02: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" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.nodePackages.statsd}/bin/statsd ${configFile}";
|
|
|
|
User = "statsd";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [pkgs.nodePackages.statsd];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|