@ -18,21 +18,25 @@ let
// optionalAttrs ( cfg . tags != null ) { tags = concatStringsSep " , " cfg . tags ; }
// cfg . extraConfig ;
makeConfigDir = entries : mapAttrsToList ( name : conf : {
source = pkgs . writeText ( baseNameOf name ) ( builtins . toJSON conf ) ;
target = " d a t a d o g - a g e n t / " + name ;
} ) ( filterAttrs ( name : conf : conf != null ) entries ) ;
etcfiles = makeConfigDir
{ " d a t a d o g . y a m l " = ddConf ;
" c o n f . d / d i s k . y a m l " = cfg . diskConfig ;
" c o n f . d / n e t w o r k . y a m l " = cfg . networkConfig ;
" c o n f . d / p o s t g r e s . d / c o n f . y a m l " = cfg . postgresqlConfig ;
" c o n f . d / n g i n x . d / c o n f . y a m l " = cfg . nginxConfig ;
" c o n f . d / m o n g o . d / c o n f . y a m l " = cfg . mongoConfig ;
" c o n f . d / p r o c e s s . y a m l " = cfg . processConfig ;
" c o n f . d / j m x . y a m l " = cfg . jmxConfig ;
} ;
# Generate Datadog configuration files for each configured checks.
# This works because check configurations have predictable paths,
# and because JSON is a valid subset of YAML.
makeCheckConfigs = entries : mapAttrsToList ( name : conf : {
source = pkgs . writeText " ${ name } - c h e c k - c o n f . y a m l " ( builtins . toJSON conf ) ;
target = " d a t a d o g - a g e n t / c o n f . d / ${ name } . d / c o n f . y a m l " ;
} ) entries ;
defaultChecks = {
disk = cfg . diskCheck ;
network = cfg . networkCheck ;
} ;
# Assemble all check configurations and the top-level agent
# configuration.
etcfiles = with pkgs ; with builtins ; [ {
source = writeText " d a t a d o g . y a m l " ( toJSON ddConf ) ;
target = " d a t a d o g - a g e n t / d a t a d o g . y a m l " ;
} ] ++ makeCheckConfigs ( cfg . checks // defaultChecks ) ;
in {
options . services . datadog-agent = {
@ -93,62 +97,65 @@ in {
'' ;
} ;
diskConfig = mkOption {
checks = mkOption {
description = ''
Configuration for all Datadog checks . Keys of this attribute
set will be used as the name of the check to create the
appropriate configuration in ` conf . d / $ check.d/conf.yaml ` .
The configuration is converted into JSON from the plain Nix
language configuration , meaning that you should write
configuration adhering to Datadog's documentation - but in Nix
language .
Refer to the implementation of this module ( specifically the
definition of ` defaultChecks ` ) for an example .
Note : The ' disk' and ' network' check are configured in
separate options because they exist by default . Attempting to
override their configuration here will have no effect .
'' ;
example = {
http_check = {
init_config = null ; # sic!
instances = [
{
name = " s o m e - s e r v i c e " ;
url = " h t t p : / / l o c a l h o s t : 1 3 3 7 / h e a l t h z " ;
tags = [ " s o m e - s e r v i c e " ] ;
}
] ;
} ;
} ;
default = { } ;
# sic! The structure of the values is up to the check, so we can
# not usefully constrain the type further.
type = with types ; attrsOf attrs ;
} ;
diskCheck = mkOption {
description = " D i s k c h e c k c o n f i g " ;
type = types . attrs ;
default = {
init_config = { } ;
instances = [ { use-mount = " n o " ; } ] ;
} ;
} ;
} ;
networkConfig = mkOption {
networkCheck = mkOption {
description = " N e t w o r k c h e c k c o n f i g " ;
type = types . attrs ;
default = {
init_config = { } ;
# Network check only supports one configured instance
instances = [ { collect_connection_state = false ;
excluded_interfaces = [ " l o " " l o 0 " ] ; } ] ;
excluded_interfaces = [ " l o " " l o 0 " ] ; } ] ;
} ;
} ;
postgresqlConfig = mkOption {
description = " D a t a d o g P o s t g r e S Q L i n t e g r a t i o n c o n f i g u r a t i o n " ;
default = null ;
type = types . nullOr types . attrs ;
} ;
nginxConfig = mkOption {
description = " D a t a d o g n g i n x i n t e g r a t i o n c o n f i g u r a t i o n " ;
default = null ;
type = types . nullOr types . attrs ;
} ;
mongoConfig = mkOption {
description = " M o n g o D B i n t e g r a t i o n c o n f i g u r a t i o n " ;
default = null ;
type = types . nullOr types . attrs ;
} ;
jmxConfig = mkOption {
description = " J M X i n t e g r a t i o n c o n f i g u r a t i o n " ;
default = null ;
type = types . nullOr types . attrs ;
} ;
processConfig = mkOption {
description = ''
Process integration configuration
See http://docs.datadoghq.com/integrations/process/
'' ;
default = null ;
type = types . nullOr types . attrs ;
} ;
} ;
config = mkIf cfg . enable {
environment . systemPackages = [ cfg . package pkgs . sysstat pkgs . procps ] ;
@ -189,7 +196,7 @@ in {
serviceConfig . PermissionsStartOnly = true ;
} ;
dd-jmxfetch = lib . mkIf ( cfg . jmxConfig != null ) ( makeService {
dd-jmxfetch = lib . mkIf ( lib . hasAttr " j m x " cfg . checks ) ( makeService {
description = " D a t a d o g J M X F e t c h e r " ;
path = [ cfg . package pkgs . python pkgs . sysstat pkgs . procps pkgs . jdk ] ;
serviceConfig . ExecStart = " ${ cfg . package } / b i n / d d - j m x f e t c h " ;