summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/statsd.nix
blob: 120c8860d57152cc714829cf5a2c04139353eae0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{ config, pkgs, ... }:

with pkgs.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.uniq types.string;
    };

    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.uniq types.string;
    };

    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 = "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];

  };

}