nixos: overhaul datadog module
This overhauls the Datadog module a bit to be much more useful. In particular, it adds support for nginx and postgresql monitoring integrations to dd-agent. These have to exist in separate files under /etc/dd-agent, so the module just exposes then as separate options. In the future, more integrations could be added this way. In the process of doing this, I also had to rename the dd-agent user to datadog. Note the UIDs did not change, so this is strictly backwards compatible. The reason for this is to make it easier to create a 'datadog' postgres user with access to pg_stats, as 'dd-agent' typically isn't a valid username. This allows the out of the box configurations to be used. Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
parent
e67cc9ba07
commit
368a677c97
@ -84,7 +84,7 @@
|
|||||||
postgres = 71;
|
postgres = 71;
|
||||||
smbguest = 74;
|
smbguest = 74;
|
||||||
varnish = 75;
|
varnish = 75;
|
||||||
dd-agent = 76;
|
datadog = 76;
|
||||||
lighttpd = 77;
|
lighttpd = 77;
|
||||||
lightdm = 78;
|
lightdm = 78;
|
||||||
freenet = 79;
|
freenet = 79;
|
||||||
@ -201,7 +201,7 @@
|
|||||||
vboxsf = 73;
|
vboxsf = 73;
|
||||||
smbguest = 74;
|
smbguest = 74;
|
||||||
varnish = 75;
|
varnish = 75;
|
||||||
dd-agent = 76;
|
datadog = 76;
|
||||||
lighttpd = 77;
|
lighttpd = 77;
|
||||||
lightdm = 78;
|
lightdm = 78;
|
||||||
freenet = 79;
|
freenet = 79;
|
||||||
|
@ -5,54 +5,113 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.services.dd-agent;
|
cfg = config.services.dd-agent;
|
||||||
|
|
||||||
datadog_conf = pkgs.runCommand "datadog.conf" {} ''
|
ddConf = pkgs.writeText "datadog.conf" ''
|
||||||
sed -e 's|^api_key:|api_key: ${cfg.api_key}|' ${optionalString (cfg.hostname != null)
|
[Main]
|
||||||
"-e 's|^#hostname: mymachine.mydomain|hostname: ${cfg.hostname}|'"
|
dd_url: https://app.datadoghq.com
|
||||||
} ${pkgs.dd-agent}/etc/dd-agent/datadog.conf.example > $out
|
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
|
||||||
|
|
||||||
|
# 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
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
postgresqlConfig = pkgs.writeText "postgres.yaml" cfg.postgresqlConfig;
|
||||||
|
nginxConfig = pkgs.writeText "nginx.yaml" cfg.nginxConfig;
|
||||||
|
|
||||||
|
etcfiles =
|
||||||
|
[ { source = ddConf;
|
||||||
|
target = "dd-agent/datadog.conf";
|
||||||
|
} ] ++
|
||||||
|
(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";
|
||||||
|
});
|
||||||
|
|
||||||
in {
|
in {
|
||||||
options.services.dd-agent = {
|
options.services.dd-agent = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
description = "Whether to enable the dd-agent montioring service";
|
description = "Whether to enable the dd-agent montioring service";
|
||||||
|
|
||||||
default = false;
|
default = false;
|
||||||
|
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
};
|
};
|
||||||
|
|
||||||
# !!! This gets stored in the store (world-readable), wish we had https://github.com/NixOS/nix/issues/8
|
|
||||||
api_key = mkOption {
|
api_key = mkOption {
|
||||||
description = "The Datadog API key to associate the agent with your account";
|
description = "The Datadog API key to associate the agent with your account";
|
||||||
|
|
||||||
example = "ae0aa6a8f08efa988ba0a17578f009ab";
|
example = "ae0aa6a8f08efa988ba0a17578f009ab";
|
||||||
|
|
||||||
type = types.str;
|
type = types.str;
|
||||||
};
|
};
|
||||||
|
|
||||||
hostname = mkOption {
|
hostname = mkOption {
|
||||||
description = "The hostname to show in the Datadog dashboard (optional)";
|
description = "The hostname to show in the Datadog dashboard (optional)";
|
||||||
|
|
||||||
default = null;
|
default = null;
|
||||||
|
|
||||||
example = "mymachine.mydomain";
|
example = "mymachine.mydomain";
|
||||||
|
type = types.uniq (types.nullOr types.string);
|
||||||
|
};
|
||||||
|
|
||||||
|
postgresqlConfig = mkOption {
|
||||||
|
description = "Datadog PostgreSQL integration configuration";
|
||||||
|
default = null;
|
||||||
|
type = types.uniq (types.nullOr types.string);
|
||||||
|
};
|
||||||
|
|
||||||
|
nginxConfig = mkOption {
|
||||||
|
description = "Datadog nginx integration configuration";
|
||||||
|
default = null;
|
||||||
type = types.uniq (types.nullOr types.string);
|
type = types.uniq (types.nullOr types.string);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.etc = [ { source = datadog_conf; target = "dd-agent/datadog.conf"; } ];
|
|
||||||
environment.systemPackages = [ pkgs."dd-agent" pkgs.sysstat pkgs.procps ];
|
environment.systemPackages = [ pkgs."dd-agent" pkgs.sysstat pkgs.procps ];
|
||||||
|
|
||||||
users.extraUsers."dd-agent" = {
|
users.extraUsers.datadog = {
|
||||||
description = "Datadog Agent User";
|
description = "Datadog Agent User";
|
||||||
uid = config.ids.uids.dd-agent;
|
uid = config.ids.uids.datadog;
|
||||||
group = "dd-agent";
|
group = "datadog";
|
||||||
home = "/var/log/datadog/";
|
home = "/var/log/datadog/";
|
||||||
createHome = true;
|
createHome = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.extraGroups.dd-agent.gid = config.ids.gids.dd-agent;
|
users.extraGroups.datadog.gid = config.ids.gids.datadog;
|
||||||
|
|
||||||
systemd.services.dd-agent = {
|
systemd.services.dd-agent = {
|
||||||
description = "Datadog agent monitor";
|
description = "Datadog agent monitor";
|
||||||
@ -60,12 +119,12 @@ in {
|
|||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.dd-agent}/bin/dd-agent foreground";
|
ExecStart = "${pkgs.dd-agent}/bin/dd-agent foreground";
|
||||||
User = "dd-agent";
|
User = "datadog";
|
||||||
Group = "dd-agent";
|
Group = "datadog";
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
RestartSec = 2;
|
RestartSec = 2;
|
||||||
};
|
};
|
||||||
restartTriggers = [ pkgs.dd-agent datadog_conf ];
|
restartTriggers = [ pkgs.dd-agent ddConf postgresqlConfig nginxConfig ];
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.dogstatsd = {
|
systemd.services.dogstatsd = {
|
||||||
@ -74,14 +133,16 @@ in {
|
|||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.dd-agent}/bin/dogstatsd start";
|
ExecStart = "${pkgs.dd-agent}/bin/dogstatsd start";
|
||||||
User = "dd-agent";
|
User = "datadog";
|
||||||
Group = "dd-agent";
|
Group = "datadog";
|
||||||
Type = "forking";
|
Type = "forking";
|
||||||
PIDFile = "/tmp/dogstatsd.pid";
|
PIDFile = "/tmp/dogstatsd.pid";
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
RestartSec = 2;
|
RestartSec = 2;
|
||||||
};
|
};
|
||||||
restartTriggers = [ pkgs.dd-agent datadog_conf ];
|
restartTriggers = [ pkgs.dd-agent ddConf postgresqlConfig nginxConfig ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
environment.etc = etcfiles;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{ stdenv, fetchurl, python, sysstat, unzip, tornado, makeWrapper }:
|
{ stdenv, fetchurl, python, pythonPackages, sysstat, unzip, tornado
|
||||||
|
, makeWrapper }:
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
version = "4.2.1";
|
version = "4.2.1";
|
||||||
@ -9,7 +10,7 @@ stdenv.mkDerivation rec {
|
|||||||
sha256 = "0s1lg7rqx86z0y111105gwkknzplq149cxd7v3yg30l22wn68dmv";
|
sha256 = "0s1lg7rqx86z0y111105gwkknzplq149cxd7v3yg30l22wn68dmv";
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = [ python unzip makeWrapper ];
|
buildInputs = [ python unzip makeWrapper pythonPackages.psycopg2 ];
|
||||||
propagatedBuildInputs = [ python tornado ];
|
propagatedBuildInputs = [ python tornado ];
|
||||||
|
|
||||||
postUnpack = "export sourceRoot=$sourceRoot/packaging";
|
postUnpack = "export sourceRoot=$sourceRoot/packaging";
|
||||||
@ -21,18 +22,19 @@ stdenv.mkDerivation rec {
|
|||||||
postInstall = ''
|
postInstall = ''
|
||||||
mv $out/usr/* $out
|
mv $out/usr/* $out
|
||||||
rmdir $out/usr
|
rmdir $out/usr
|
||||||
wrapProgram $out/bin/dd-forwarder --prefix PYTHONPATH : $PYTHONPATH
|
wrapProgram $out/bin/dd-forwarder \
|
||||||
|
--prefix PYTHONPATH : $PYTHONPATH
|
||||||
|
wrapProgram $out/bin/dd-agent \
|
||||||
|
--prefix PYTHONPATH : $PYTHONPATH
|
||||||
|
wrapProgram $out/bin/dogstatsd \
|
||||||
|
--prefix PYTHONPATH : $PYTHONPATH
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "Event collector for the DataDog analysis service";
|
description = "Event collector for the DataDog analysis service";
|
||||||
|
homepage = http://www.datadoghq.com;
|
||||||
homepage = http://www.datadoghq.com;
|
license = stdenv.lib.licenses.bsd3;
|
||||||
|
platforms = stdenv.lib.platforms.all;
|
||||||
maintainers = [ stdenv.lib.maintainers.iElectric ];
|
maintainers = with stdenv.lib.maintainers; [ thoughtpolice iElectric ];
|
||||||
|
|
||||||
license = stdenv.lib.licenses.bsd3;
|
|
||||||
|
|
||||||
platforms = stdenv.lib.platforms.all;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user