summary refs log tree commit diff
path: root/modules/services/monitoring/dd-agent.nix
blob: c6ab1ca0a3a0669b94b9aeb578b953b023485b83 (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
{ config, pkgs, ... }:

with pkgs.lib;

let
  cfg = config.services.dd-agent;

  datadog-conf = pkgs.runCommand "datadog.conf" {} ''
    sed -e 's|^api_key:|api_key: ${cfg.api_key}|' ${optionalString (cfg.hostname != null)
      "-e 's|^#hostname: mymachine.mydomain|hostname: ${cfg.hostname}|'"
    } ${pkgs.dd-agent}/etc/dd-agent/datadog.conf.example > $out
  '';
in {
  options.services.dd-agent = {
    enable = mkOption {
      description = "Whether to enable the dd-agent montioring service";

      default = false;

      type = types.bool;
    };

    # !!! This gets stored in the store (world-readable), wish we had https://github.com/NixOS/nix/issues/8
    api_key = mkOption {
      description = "The Datadog API key to associate the agent with your account";

      example = "ae0aa6a8f08efa988ba0a17578f009ab";

      type = types.uniq types.string;
    };

    hostname = mkOption {
      description = "The hostname to show in the Datadog dashboard (optional)";

      default = null;

      example = "mymachine.mydomain";

      type = types.uniq (types.nullOr types.string);
    };
  };

  config = mkIf cfg.enable {
    environment.etc = [ { source = datadog-conf; target = "dd-agent/datadog.conf"; } ];

    systemd.services.dd-agent = {
      description = "Datadog agent monitor";

      path = [ pkgs.sysstat pkgs.procps ];

      wantedBy = [ "multi-user.target" ];

      serviceConfig.ExecStart = "${pkgs.dd-agent}/bin/dd-agent foreground";

      restartTriggers = [ pkgs.dd-agent ];
    };
  };
}