nixos/statsd: add support for external backends, fix a few options

This commit is contained in:
Jaka Hudoklin 2014-09-11 18:11:16 +02:00
parent dbae0b628e
commit bc6b180d90
1 changed files with 22 additions and 10 deletions

View File

@ -8,13 +8,20 @@ let
configFile = pkgs.writeText "statsd.conf" '' configFile = pkgs.writeText "statsd.conf" ''
{ {
host: "${cfg.host}", address: "${cfg.host}",
port: "${toString cfg.port}", port: "${toString cfg.port}",
mgmt_address: "${cfg.mgmt_address}", mgmt_address: "${cfg.mgmt_address}",
mgmt_port: "${toString cfg.mgmt_port}", mgmt_port: "${toString cfg.mgmt_port}",
backends: [${concatMapStrings (el: ''"./backends/${el}",'') cfg.backends}], backends: [${concatMapStringsSep "," (el: if (nixType el) == "string" then ''"./backends/${el}"'' else ''"${head el.names}"'') cfg.backends}],
graphiteHost: "${cfg.graphiteHost}", ${optionalString (cfg.graphiteHost!=null) ''graphiteHost: "${cfg.graphiteHost}",''}
graphitePort: "${toString cfg.graphitePort}", ${optionalString (cfg.graphitePort!=null) ''graphitePort: "${toString cfg.graphitePort}",''}
console: {
prettyprint: false
},
log: {
backend: "syslog"
},
automaticConfigReload: false${optionalString (cfg.extraConfig != null) ","}
${cfg.extraConfig} ${cfg.extraConfig}
} }
''; '';
@ -60,24 +67,26 @@ in
backends = mkOption { backends = mkOption {
description = "List of backends statsd will use for data persistance"; description = "List of backends statsd will use for data persistance";
default = ["graphite"]; default = ["graphite"];
example = ["graphite" pkgs.nodePackages."statsd-influxdb-backend"];
type = types.listOf (types.either types.str types.package);
}; };
graphiteHost = mkOption { graphiteHost = mkOption {
description = "Hostname or IP of Graphite server"; description = "Hostname or IP of Graphite server";
default = config.services.graphite.web.host; default = null;
type = types.str; type = types.nullOr types.str;
}; };
graphitePort = mkOption { graphitePort = mkOption {
description = "Port of Graphite server (i.e. carbon-cache)."; description = "Port of Graphite server (i.e. carbon-cache).";
default = 2003; default = null;
type = types.uniq types.int; type = types.nullOr types.int;
}; };
extraConfig = mkOption { extraConfig = mkOption {
default = "";
description = "Extra configuration options for statsd"; description = "Extra configuration options for statsd";
type = types.str; default = "";
type = types.nullOr types.str;
}; };
}; };
@ -95,6 +104,9 @@ in
systemd.services.statsd = { systemd.services.statsd = {
description = "Statsd Server"; description = "Statsd Server";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
environment = {
NODE_PATH=concatMapStringsSep ":" (el: "${el}/lib/node_modules") (filter (el: (nixType el) != "string") cfg.backends);
};
serviceConfig = { serviceConfig = {
ExecStart = "${pkgs.nodePackages.statsd}/bin/statsd ${configFile}"; ExecStart = "${pkgs.nodePackages.statsd}/bin/statsd ${configFile}";
User = "statsd"; User = "statsd";