2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-01-08 22:19:51 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-01-08 22:19:51 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.dd-agent;
|
|
|
|
|
2013-06-29 19:33:44 +02:00
|
|
|
datadog_conf = pkgs.runCommand "datadog.conf" {} ''
|
2013-01-08 22:19:51 +01:00
|
|
|
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";
|
|
|
|
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-01-08 22:19:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2013-06-29 19:33:44 +02:00
|
|
|
environment.etc = [ { source = datadog_conf; target = "dd-agent/datadog.conf"; } ];
|
|
|
|
environment.systemPackages = [ pkgs."dd-agent" pkgs.sysstat pkgs.procps ];
|
2013-01-08 22:19:51 +01:00
|
|
|
|
2013-02-27 15:25:37 +01:00
|
|
|
users.extraUsers."dd-agent" = {
|
|
|
|
description = "Datadog Agent User";
|
2013-08-23 11:33:24 +02:00
|
|
|
uid = config.ids.uids.dd-agent;
|
2013-02-27 15:25:37 +01:00
|
|
|
group = "dd-agent";
|
2013-06-29 18:45:25 +02:00
|
|
|
home = "/var/log/datadog/";
|
|
|
|
createHome = true;
|
2013-02-27 15:25:37 +01:00
|
|
|
};
|
|
|
|
|
2013-08-23 11:33:24 +02:00
|
|
|
users.extraGroups.dd-agent.gid = config.ids.gids.dd-agent;
|
2013-02-27 15:25:37 +01:00
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
systemd.services.dd-agent = {
|
2013-01-08 22:19:51 +01:00
|
|
|
description = "Datadog agent monitor";
|
2013-06-29 19:33:44 +02:00
|
|
|
path = [ pkgs."dd-agent" pkgs.python pkgs.sysstat pkgs.procps];
|
2013-01-08 22:19:51 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2013-02-27 15:25:37 +01:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.dd-agent}/bin/dd-agent foreground";
|
|
|
|
User = "dd-agent";
|
|
|
|
Group = "dd-agent";
|
2013-11-22 15:23:45 +01:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 2;
|
2013-02-27 15:25:37 +01:00
|
|
|
};
|
2013-06-29 19:33:44 +02:00
|
|
|
restartTriggers = [ pkgs.dd-agent datadog_conf ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.dogstatsd = {
|
|
|
|
description = "Datadog statsd";
|
|
|
|
path = [ pkgs."dd-agent" pkgs.python ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.dd-agent}/bin/dogstatsd start";
|
|
|
|
User = "dd-agent";
|
|
|
|
Group = "dd-agent";
|
|
|
|
Type = "forking";
|
|
|
|
PIDFile = "/tmp/dogstatsd.pid";
|
2013-11-22 15:23:45 +01:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 2;
|
2013-06-29 19:33:44 +02:00
|
|
|
};
|
|
|
|
restartTriggers = [ pkgs.dd-agent datadog_conf ];
|
2013-01-08 22:19:51 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|