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;
|
|
|
|
|
2014-05-02 07:43:27 +02: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
|
|
|
|
|
|
|
|
# proxy_host: my-proxy.com
|
|
|
|
# proxy_port: 3128
|
|
|
|
# proxy_user: user
|
|
|
|
# proxy_password: password
|
|
|
|
|
|
|
|
# tags: mytag0, mytag1
|
2015-06-03 22:21:12 +02:00
|
|
|
${optionalString (cfg.tags != null ) "tags: ${concatStringsSep "," cfg.tags }"}
|
2014-05-02 07:43:27 +02: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 22:19:51 +01:00
|
|
|
'';
|
2014-05-02 07:43:27 +02:00
|
|
|
|
2015-08-03 16:27:23 +02:00
|
|
|
diskConfig = pkgs.writeText "disk.yaml" ''
|
|
|
|
init_config:
|
|
|
|
|
|
|
|
instances:
|
|
|
|
- use_mount: no
|
|
|
|
'';
|
|
|
|
|
|
|
|
networkConfig = pkgs.writeText "network.yaml" ''
|
|
|
|
init_config:
|
|
|
|
|
|
|
|
instances:
|
|
|
|
# Network check only supports one configured instance
|
|
|
|
- collect_connection_state: false
|
|
|
|
excluded_interfaces:
|
|
|
|
- lo
|
|
|
|
- lo0
|
|
|
|
'';
|
|
|
|
|
2014-05-02 07:43:27 +02:00
|
|
|
postgresqlConfig = pkgs.writeText "postgres.yaml" cfg.postgresqlConfig;
|
|
|
|
nginxConfig = pkgs.writeText "nginx.yaml" cfg.nginxConfig;
|
2015-08-03 11:09:52 +02:00
|
|
|
mongoConfig = pkgs.writeText "mongo.yaml" cfg.mongoConfig;
|
2016-07-29 14:41:35 +02:00
|
|
|
jmxConfig = pkgs.writeText "jmx.yaml" cfg.jmxConfig;
|
2015-08-03 11:09:52 +02:00
|
|
|
|
2014-05-02 07:43:27 +02:00
|
|
|
etcfiles =
|
|
|
|
[ { source = ddConf;
|
|
|
|
target = "dd-agent/datadog.conf";
|
2015-08-03 16:27:23 +02:00
|
|
|
}
|
|
|
|
{ source = diskConfig;
|
|
|
|
target = "dd-agent/conf.d/disk.yaml";
|
|
|
|
}
|
|
|
|
{ source = networkConfig;
|
|
|
|
target = "dd-agent/conf.d/network.yaml";
|
2014-05-02 07:43:27 +02:00
|
|
|
} ] ++
|
|
|
|
(optional (cfg.postgresqlConfig != null)
|
|
|
|
{ source = postgresqlConfig;
|
|
|
|
target = "dd-agent/conf.d/postgres.yaml";
|
|
|
|
}) ++
|
|
|
|
(optional (cfg.nginxConfig != null)
|
|
|
|
{ source = nginxConfig;
|
|
|
|
target = "dd-agent/conf.d/nginx.yaml";
|
2015-08-03 11:09:52 +02:00
|
|
|
}) ++
|
|
|
|
(optional (cfg.mongoConfig != null)
|
|
|
|
{ source = mongoConfig;
|
|
|
|
target = "dd-agent/conf.d/mongo.yaml";
|
2016-07-29 14:41:35 +02:00
|
|
|
}) ++
|
|
|
|
(optional (cfg.jmxConfig != null)
|
|
|
|
{ source = jmxConfig;
|
|
|
|
target = "dd-agent/conf.d/jmx.yaml";
|
2014-05-02 07:43:27 +02:00
|
|
|
});
|
|
|
|
|
2013-01-08 22:19:51 +01:00
|
|
|
in {
|
|
|
|
options.services.dd-agent = {
|
|
|
|
enable = mkOption {
|
|
|
|
description = "Whether to enable the dd-agent montioring service";
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-06-03 22:21:12 +02: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 22:19:51 +01:00
|
|
|
hostname = mkOption {
|
|
|
|
description = "The hostname to show in the Datadog dashboard (optional)";
|
|
|
|
default = null;
|
|
|
|
example = "mymachine.mydomain";
|
2014-05-02 07:43:27 +02:00
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
};
|
|
|
|
|
|
|
|
postgresqlConfig = mkOption {
|
|
|
|
description = "Datadog PostgreSQL integration configuration";
|
|
|
|
default = null;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
};
|
2013-01-08 22:19:51 +01:00
|
|
|
|
2014-05-02 07:43:27 +02:00
|
|
|
nginxConfig = mkOption {
|
|
|
|
description = "Datadog nginx integration configuration";
|
|
|
|
default = null;
|
2013-01-08 22:19:51 +01:00
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
};
|
2015-08-03 11:09:52 +02:00
|
|
|
|
|
|
|
mongoConfig = mkOption {
|
|
|
|
description = "MongoDB integration configuration";
|
|
|
|
default = null;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
};
|
2016-07-29 14:41:35 +02:00
|
|
|
|
|
|
|
jmxConfig = mkOption {
|
|
|
|
description = "JMX integration configuration";
|
|
|
|
default = null;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
};
|
|
|
|
|
2013-01-08 22:19:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2013-06-29 19:33:44 +02:00
|
|
|
environment.systemPackages = [ pkgs."dd-agent" pkgs.sysstat pkgs.procps ];
|
2013-01-08 22:19:51 +01:00
|
|
|
|
2014-05-02 07:43:27 +02:00
|
|
|
users.extraUsers.datadog = {
|
2013-02-27 15:25:37 +01:00
|
|
|
description = "Datadog Agent User";
|
2014-05-02 07:43:27 +02:00
|
|
|
uid = config.ids.uids.datadog;
|
|
|
|
group = "datadog";
|
2013-06-29 18:45:25 +02:00
|
|
|
home = "/var/log/datadog/";
|
|
|
|
createHome = true;
|
2013-02-27 15:25:37 +01:00
|
|
|
};
|
|
|
|
|
2014-05-02 07:43:27 +02:00
|
|
|
users.extraGroups.datadog.gid = config.ids.gids.datadog;
|
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";
|
2015-08-03 11:09:52 +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";
|
2014-05-02 07:43:27 +02:00
|
|
|
User = "datadog";
|
|
|
|
Group = "datadog";
|
2013-11-22 15:23:45 +01:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 2;
|
2013-02-27 15:25:37 +01:00
|
|
|
};
|
2016-07-29 14:41:35 +02:00
|
|
|
restartTriggers = [ pkgs.dd-agent ddConf diskConfig networkConfig postgresqlConfig nginxConfig mongoConfig jmxConfig ];
|
2013-06-29 19:33:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.dogstatsd = {
|
|
|
|
description = "Datadog statsd";
|
2014-05-18 13:00:33 +02:00
|
|
|
path = [ pkgs."dd-agent" pkgs.python pkgs.procps ];
|
2013-06-29 19:33:44 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.dd-agent}/bin/dogstatsd start";
|
2014-05-02 07:43:27 +02:00
|
|
|
User = "datadog";
|
|
|
|
Group = "datadog";
|
2013-06-29 19:33:44 +02:00
|
|
|
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
|
|
|
};
|
2016-07-29 14:41:35 +02:00
|
|
|
restartTriggers = [ pkgs.dd-agent ddConf diskConfig networkConfig postgresqlConfig nginxConfig mongoConfig jmxConfig ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.dd-jmxfetch = lib.mkIf (cfg.jmxConfig != null) {
|
|
|
|
description = "Datadog JMX Fetcher";
|
|
|
|
path = [ pkgs."dd-agent" pkgs.python pkgs.sysstat pkgs.procps pkgs.jdk ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.dd-agent}/bin/dd-jmxfetch";
|
|
|
|
User = "datadog";
|
|
|
|
Group = "datadog";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 2;
|
|
|
|
};
|
|
|
|
restartTriggers = [ pkgs.dd-agent ddConf diskConfig networkConfig postgresqlConfig nginxConfig mongoConfig jmxConfig ];
|
2013-01-08 22:19:51 +01:00
|
|
|
};
|
2014-05-02 07:43:27 +02:00
|
|
|
|
|
|
|
environment.etc = etcfiles;
|
2013-01-08 22:19:51 +01:00
|
|
|
};
|
|
|
|
}
|