From 5894f26c81cafe0c81fb35e1b09f3ab45526b6a1 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Wed, 21 Aug 2013 11:43:37 +0200 Subject: [PATCH] Add statsd, simple daemon for easy stats aggregation --- modules/misc/ids.nix | 1 + modules/module-list.nix | 1 + modules/services/monitoring/statsd.nix | 94 ++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 modules/services/monitoring/statsd.nix diff --git a/modules/misc/ids.nix b/modules/misc/ids.nix index d850ccc7276..91cfb88cebd 100644 --- a/modules/misc/ids.nix +++ b/modules/misc/ids.nix @@ -81,6 +81,7 @@ in supybot = 65; iodined = 66; graphite = 68; + statsd = 69; # When adding a uid, make sure it doesn't match an existing gid. diff --git a/modules/module-list.nix b/modules/module-list.nix index 37e68f06d3a..20ad0a014f1 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -125,6 +125,7 @@ ./services/monitoring/monit.nix ./services/monitoring/nagios/default.nix ./services/monitoring/smartd.nix + ./services/monitoring/statsd.nix ./services/monitoring/systemhealth.nix ./services/monitoring/ups.nix ./services/monitoring/uptime.nix diff --git a/modules/services/monitoring/statsd.nix b/modules/services/monitoring/statsd.nix new file mode 100644 index 00000000000..a3266605671 --- /dev/null +++ b/modules/services/monitoring/statsd.nix @@ -0,0 +1,94 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + cfg = config.services.statsd; + + configFile = pkgs.writeText "statsd.conf" '' + { + host: "${cfg.host}", + port: "${toString cfg.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.uniq types.string; + }; + + port = mkOption { + description = "Port that stats listens for messages on over UDP"; + default = 8125; + 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 = "127.0.0.1"; + type = types.uniq types.string; + }; + + graphitePort = mkOption { + description = "Port of Graphite server"; + default = 2003; + type = types.uniq types.int; + }; + + extraConfig = mkOption { + default = ""; + description = "Extra configuration options for statsd"; + type = types.uniq types.string; + }; + + }; + + ###### 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]; + + }; + +}