nixpkgs/nixos/modules/services/monitoring/statsd.nix
Rok Garbas 2de0dc1a18 statsd: updated package and nixos service
* package statsd node packages separatly since they actually require
  nodejs-0.10 or nodejs-0.12 to work (which is ... well old)

* remove statsd packages and its backends from "global" node-packages.json.
  i did not rebuild it since for some reason npm2nix command fails. next time
  somebody will rerun npm2nix statsd packages are going to be removed.

* statsd service: backends are now provided as strings and not anymore as
  packages.
2015-11-27 21:42:21 +01:00

138 lines
3.3 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.statsd;
isBuiltinBackend = name:
builtins.elem name [ "graphite" "console" "repeater" ];
configFile = pkgs.writeText "statsd.conf" ''
{
address: "${cfg.host}",
port: "${toString cfg.port}",
mgmt_address: "${cfg.mgmt_address}",
mgmt_port: "${toString cfg.mgmt_port}",
backends: [${
concatMapStringsSep "," (name:
if (isBuiltinBackend name)
then ''"./backends/${name}"''
else ''"${name}"''
) 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) ","}
${cfg.extraConfig}
}
'';
in
{
###### interface
options.services.statsd = {
enable = mkOption {
description = "Whether to enable statsd stats aggregation service";
default = false;
type = types.bool;
};
host = mkOption {
description = "Address that statsd listens on over UDP";
default = "127.0.0.1";
type = types.str;
};
port = mkOption {
description = "Port that stats listens for messages on over UDP";
default = 8125;
type = types.int;
};
mgmt_address = mkOption {
description = "Address to run management TCP interface on";
default = "127.0.0.1";
type = types.str;
};
mgmt_port = mkOption {
description = "Port to run the management TCP interface on";
default = 8126;
type = types.int;
};
backends = mkOption {
description = "List of backends statsd will use for data persistence";
default = [];
example = [
"graphite"
"console"
"repeater"
"statsd-librato-backend"
"stackdriver-statsd-backend"
"statsd-influxdb-backend"
];
type = types.listOf types.str;
};
graphiteHost = mkOption {
description = "Hostname or IP of Graphite server";
default = null;
type = types.nullOr types.str;
};
graphitePort = mkOption {
description = "Port of Graphite server (i.e. carbon-cache).";
default = null;
type = types.nullOr types.int;
};
extraConfig = mkOption {
description = "Extra configuration options for statsd";
default = "";
type = types.nullOr types.str;
};
};
###### 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" ];
environment = {
NODE_PATH=concatMapStringsSep ":"
(pkg: "${builtins.getAttr pkg pkgs.statsd.nodePackages}/lib/node_modules")
(filter (name: !isBuiltinBackend name) cfg.backends);
};
serviceConfig = {
ExecStart = "${pkgs.statsd}/bin/statsd ${configFile}";
User = "statsd";
};
};
environment.systemPackages = [ pkgs.statsd ];
};
}