2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-01-08 21:19:51 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-01-08 21:19:51 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.dd-agent;
|
|
|
|
|
2014-05-02 06:43:27 +01:00
|
|
|
ddConf = pkgs.writeText "datadog.conf" ''
|
|
|
|
[Main]
|
|
|
|
dd_url: https://app.datadoghq.com
|
|
|
|
skip_ssl_validation: no
|
|
|
|
api_key: ${cfg.api_key}
|
|
|
|
${optionalString (cfg.hostname != null) "hostname: ${cfg.hostname}"}
|
|
|
|
|
|
|
|
collector_log_file: /var/log/datadog/collector.log
|
|
|
|
forwarder_log_file: /var/log/datadog/forwarder.log
|
|
|
|
dogstatsd_log_file: /var/log/datadog/dogstatsd.log
|
|
|
|
pup_log_file: /var/log/datadog/pup.log
|
2017-06-03 12:27:56 +01:00
|
|
|
|
|
|
|
# proxy_host: my-proxy.com
|
|
|
|
# proxy_port: 3128
|
|
|
|
# proxy_user: user
|
|
|
|
# proxy_password: password
|
|
|
|
|
|
|
|
# tags: mytag0, mytag1
|
2017-10-05 23:33:18 +01:00
|
|
|
${optionalString (cfg.tags != null ) "tags: ${concatStringsSep ", " cfg.tags }"}
|
2017-06-03 12:27:56 +01:00
|
|
|
|
|
|
|
# collect_ec2_tags: no
|
|
|
|
# recent_point_threshold: 30
|
|
|
|
# use_mount: no
|
|
|
|
# listen_port: 17123
|
|
|
|
# graphite_listen_port: 17124
|
|
|
|
# non_local_traffic: no
|
|
|
|
# use_curl_http_client: False
|
|
|
|
# bind_host: localhost
|
|
|
|
|
|
|
|
# use_pup: no
|
|
|
|
# pup_port: 17125
|
|
|
|
# pup_interface: localhost
|
|
|
|
# pup_url: http://localhost:17125
|
|
|
|
|
|
|
|
# dogstatsd_port : 8125
|
|
|
|
# dogstatsd_interval : 10
|
|
|
|
# dogstatsd_normalize : yes
|
|
|
|
# statsd_forward_host: address_of_own_statsd_server
|
|
|
|
# statsd_forward_port: 8125
|
|
|
|
|
|
|
|
# device_blacklist_re: .*\/dev\/mapper\/lxc-box.*
|
|
|
|
|
|
|
|
# ganglia_host: localhost
|
|
|
|
# ganglia_port: 8651
|
2013-01-08 21:19:51 +00:00
|
|
|
'';
|
2014-05-02 06:43:27 +01:00
|
|
|
|
2017-06-03 12:27:56 +01:00
|
|
|
diskConfig = pkgs.writeText "disk.yaml" ''
|
|
|
|
init_config:
|
|
|
|
|
|
|
|
instances:
|
|
|
|
- use_mount: no
|
|
|
|
'';
|
2018-05-24 09:58:28 +01:00
|
|
|
|
2017-06-03 12:27:56 +01:00
|
|
|
networkConfig = pkgs.writeText "network.yaml" ''
|
|
|
|
init_config:
|
|
|
|
|
|
|
|
instances:
|
|
|
|
# Network check only supports one configured instance
|
|
|
|
- collect_connection_state: false
|
|
|
|
excluded_interfaces:
|
|
|
|
- lo
|
|
|
|
- lo0
|
|
|
|
'';
|
2018-05-24 09:58:28 +01:00
|
|
|
|
2017-06-03 12:27:56 +01:00
|
|
|
postgresqlConfig = pkgs.writeText "postgres.yaml" cfg.postgresqlConfig;
|
|
|
|
nginxConfig = pkgs.writeText "nginx.yaml" cfg.nginxConfig;
|
|
|
|
mongoConfig = pkgs.writeText "mongo.yaml" cfg.mongoConfig;
|
|
|
|
jmxConfig = pkgs.writeText "jmx.yaml" cfg.jmxConfig;
|
|
|
|
processConfig = pkgs.writeText "process.yaml" cfg.processConfig;
|
2018-05-24 09:58:28 +01:00
|
|
|
|
2014-05-02 06:43:27 +01:00
|
|
|
etcfiles =
|
2017-06-03 12:27:56 +01:00
|
|
|
let
|
|
|
|
defaultConfd = import ./dd-agent-defaults.nix;
|
2019-09-14 18:51:29 +01:00
|
|
|
in
|
|
|
|
listToAttrs (map (f: {
|
|
|
|
name = "dd-agent/conf.d/${f}";
|
|
|
|
value.source = "${pkgs.dd-agent}/agent/conf.d-system/${f}";
|
|
|
|
}) defaultConfd) //
|
|
|
|
{
|
|
|
|
"dd-agent/datadog.conf".source = ddConf;
|
|
|
|
"dd-agent/conf.d/disk.yaml".source = diskConfig;
|
|
|
|
"dd-agent/conf.d/network.yaml".source = networkConfig;
|
|
|
|
} //
|
|
|
|
(optionalAttrs (cfg.postgresqlConfig != null)
|
|
|
|
{
|
|
|
|
"dd-agent/conf.d/postgres.yaml".source = postgresqlConfig;
|
|
|
|
}) //
|
|
|
|
(optionalAttrs (cfg.nginxConfig != null)
|
|
|
|
{
|
|
|
|
"dd-agent/conf.d/nginx.yaml".source = nginxConfig;
|
|
|
|
}) //
|
|
|
|
(optionalAttrs (cfg.mongoConfig != null)
|
|
|
|
{
|
|
|
|
"dd-agent/conf.d/mongo.yaml".source = mongoConfig;
|
|
|
|
}) //
|
|
|
|
(optionalAttrs (cfg.processConfig != null)
|
|
|
|
{
|
|
|
|
"dd-agent/conf.d/process.yaml".source = processConfig;
|
|
|
|
}) //
|
|
|
|
(optionalAttrs (cfg.jmxConfig != null)
|
|
|
|
{
|
|
|
|
"dd-agent/conf.d/jmx.yaml".source = jmxConfig;
|
2017-06-03 12:27:56 +01:00
|
|
|
});
|
2014-05-02 06:43:27 +01:00
|
|
|
|
2013-01-08 21:19:51 +00:00
|
|
|
in {
|
|
|
|
options.services.dd-agent = {
|
|
|
|
enable = mkOption {
|
2018-05-05 13:46:10 +01:00
|
|
|
description = ''
|
|
|
|
Whether to enable the dd-agent v5 monitoring service.
|
|
|
|
For datadog-agent v6, see <option>services.datadog-agent.enable</option>.
|
|
|
|
'';
|
2013-01-08 21:19:51 +00:00
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
api_key = mkOption {
|
2018-05-05 13:46:10 +01:00
|
|
|
description = ''
|
|
|
|
The Datadog API key to associate the agent with your account.
|
|
|
|
|
|
|
|
Warning: this key is stored in cleartext within the world-readable
|
|
|
|
Nix store! Consider using the new v6
|
|
|
|
<option>services.datadog-agent</option> module instead.
|
|
|
|
'';
|
2013-01-08 21:19:51 +00:00
|
|
|
example = "ae0aa6a8f08efa988ba0a17578f009ab";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-01-08 21:19:51 +00:00
|
|
|
};
|
|
|
|
|
2015-06-03 21:21:12 +01:00
|
|
|
tags = mkOption {
|
|
|
|
description = "The tags to mark this Datadog agent";
|
|
|
|
example = [ "test" "service" ];
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
};
|
|
|
|
|
2013-01-08 21:19:51 +00:00
|
|
|
hostname = mkOption {
|
|
|
|
description = "The hostname to show in the Datadog dashboard (optional)";
|
|
|
|
default = null;
|
|
|
|
example = "mymachine.mydomain";
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.nullOr types.str;
|
2014-05-02 06:43:27 +01:00
|
|
|
};
|
|
|
|
|
2017-06-03 12:27:56 +01:00
|
|
|
postgresqlConfig = mkOption {
|
|
|
|
description = "Datadog PostgreSQL integration configuration";
|
|
|
|
default = null;
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.nullOr types.lines;
|
2017-06-03 12:27:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
nginxConfig = mkOption {
|
|
|
|
description = "Datadog nginx integration configuration";
|
|
|
|
default = null;
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.nullOr types.lines;
|
2017-06-03 12:27:56 +01:00
|
|
|
};
|
2018-05-24 09:58:28 +01:00
|
|
|
|
2017-06-03 12:27:56 +01:00
|
|
|
mongoConfig = mkOption {
|
|
|
|
description = "MongoDB integration configuration";
|
|
|
|
default = null;
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.nullOr types.lines;
|
2017-06-03 12:27:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
jmxConfig = mkOption {
|
|
|
|
description = "JMX integration configuration";
|
|
|
|
default = null;
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.nullOr types.lines;
|
2016-07-29 13:41:35 +01:00
|
|
|
};
|
|
|
|
|
2017-06-03 12:27:56 +01:00
|
|
|
processConfig = mkOption {
|
2017-04-19 14:32:21 +01:00
|
|
|
description = ''
|
2017-06-03 12:27:56 +01:00
|
|
|
Process integration configuration
|
2019-08-08 21:48:27 +01:00
|
|
|
See <link xlink:href="https://docs.datadoghq.com/integrations/process/"/>
|
2017-04-19 14:32:21 +01:00
|
|
|
'';
|
2017-06-03 12:27:56 +01:00
|
|
|
default = null;
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.nullOr types.lines;
|
2017-04-19 14:32:21 +01:00
|
|
|
};
|
|
|
|
|
2013-01-08 21:19:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.systemPackages = [ pkgs.dd-agent pkgs.sysstat pkgs.procps ];
|
2013-01-08 21:19:51 +00:00
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users.datadog = {
|
2013-02-27 14:25:37 +00:00
|
|
|
description = "Datadog Agent User";
|
2014-05-02 06:43:27 +01:00
|
|
|
uid = config.ids.uids.datadog;
|
|
|
|
group = "datadog";
|
2013-06-29 17:45:25 +01:00
|
|
|
home = "/var/log/datadog/";
|
|
|
|
createHome = true;
|
2013-02-27 14:25:37 +00:00
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.datadog.gid = config.ids.gids.datadog;
|
2013-02-27 14:25:37 +00:00
|
|
|
|
2018-05-05 13:46:10 +01:00
|
|
|
systemd.services = let
|
|
|
|
makeService = attrs: recursiveUpdate {
|
|
|
|
path = [ pkgs.dd-agent pkgs.python pkgs.sysstat pkgs.procps pkgs.gohai ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "datadog";
|
|
|
|
Group = "datadog";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 2;
|
|
|
|
PrivateTmp = true;
|
|
|
|
};
|
|
|
|
restartTriggers = [ pkgs.dd-agent ddConf diskConfig networkConfig postgresqlConfig nginxConfig mongoConfig jmxConfig processConfig ];
|
|
|
|
} attrs;
|
|
|
|
in {
|
|
|
|
dd-agent = makeService {
|
|
|
|
description = "Datadog agent monitor";
|
|
|
|
serviceConfig.ExecStart = "${pkgs.dd-agent}/bin/dd-agent foreground";
|
2013-02-27 14:25:37 +00:00
|
|
|
};
|
2017-06-03 12:27:56 +01:00
|
|
|
|
2018-05-05 13:46:10 +01:00
|
|
|
dogstatsd = makeService {
|
|
|
|
description = "Datadog statsd";
|
|
|
|
environment.TMPDIR = "/run/dogstatsd";
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.dd-agent}/bin/dogstatsd start";
|
|
|
|
Type = "forking";
|
|
|
|
PIDFile = "/run/dogstatsd/dogstatsd.pid";
|
|
|
|
RuntimeDirectory = "dogstatsd";
|
|
|
|
};
|
2017-06-03 12:27:56 +01:00
|
|
|
};
|
2016-07-29 13:41:35 +01:00
|
|
|
|
2018-05-05 13:46:10 +01:00
|
|
|
dd-jmxfetch = lib.mkIf (cfg.jmxConfig != null) {
|
|
|
|
description = "Datadog JMX Fetcher";
|
|
|
|
path = [ pkgs.dd-agent pkgs.python pkgs.sysstat pkgs.procps pkgs.jdk ];
|
|
|
|
serviceConfig.ExecStart = "${pkgs.dd-agent}/bin/dd-jmxfetch";
|
2016-07-29 13:41:35 +01:00
|
|
|
};
|
2013-01-08 21:19:51 +00:00
|
|
|
};
|
2014-05-02 06:43:27 +01:00
|
|
|
|
|
|
|
environment.etc = etcfiles;
|
2013-01-08 21:19:51 +00:00
|
|
|
};
|
|
|
|
}
|