1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-30 17:41:12 +00:00
nixpkgs/nixos/modules/services/monitoring/statsd.nix
Eelco Dolstra 29027fd1e1 Rewrite ‘with pkgs.lib’ -> ‘with lib’
Using pkgs.lib on the spine of module evaluation is problematic
because the pkgs argument depends on the result of module
evaluation. To prevent an infinite recursion, pkgs and some of the
modules are evaluated twice, which is inefficient. Using ‘with lib’
prevents this problem.
2014-04-14 16:26:48 +02:00

109 lines
2.4 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.statsd;
configFile = pkgs.writeText "statsd.conf" ''
{
host: "${cfg.host}",
port: "${toString cfg.port}",
mgmt_address: "${cfg.mgmt_address}",
mgmt_port: "${toString cfg.mgmt_port}",
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";
type = types.str;
};
port = mkOption {
description = "Port that stats listens for messages on over UDP";
default = 8125;
type = types.uniq types.int;
};
mgmt_address = mkOption {
description = "Address to run managment 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.uniq types.int;
};
backends = mkOption {
description = "List of backends statsd will use for data persistance";
default = ["graphite"];
};
graphiteHost = mkOption {
description = "Hostname or IP of Graphite server";
default = config.services.graphite.web.host;
type = types.str;
};
graphitePort = mkOption {
description = "Port of Graphite server";
default = config.services.graphite.web.port;
type = types.uniq types.int;
};
extraConfig = mkOption {
default = "";
description = "Extra configuration options for statsd";
type = 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" ];
serviceConfig = {
ExecStart = "${pkgs.nodePackages.statsd}/bin/statsd ${configFile}";
User = "statsd";
};
};
environment.systemPackages = [pkgs.nodePackages.statsd];
};
}