about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/datadog-agent.nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2018-08-09 16:01:12 +0200
committerVincent Ambo <mail@tazj.in>2018-08-09 17:25:23 +0200
commit5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe (patch)
treed5b07c63cbf7bf7a0977155193570eaf1f98822e /nixos/modules/services/monitoring/datadog-agent.nix
parent924016f45f0fbe61b6a0db97ce9f2b41b8645dda (diff)
downloadnixlib-5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe.tar
nixlib-5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe.tar.gz
nixlib-5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe.tar.bz2
nixlib-5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe.tar.lz
nixlib-5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe.tar.xz
nixlib-5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe.tar.zst
nixlib-5b748bd8fa517fa16d0fdb60fd5a83d4d1717efe.zip
nixos/datadog-agent: Add option to configure datadog integrations
Introduces an option `services.datadog-agent.extraIntegrations` that
can be set to include additional Datadog agent integrations from the
integrations-core repository.

Documentation and an example is provided with the change.

Relates to NixOS/nixpkgs#40399
Diffstat (limited to 'nixos/modules/services/monitoring/datadog-agent.nix')
-rw-r--r--nixos/modules/services/monitoring/datadog-agent.nix48
1 files changed, 38 insertions, 10 deletions
diff --git a/nixos/modules/services/monitoring/datadog-agent.nix b/nixos/modules/services/monitoring/datadog-agent.nix
index 6b7359934f5c..f8ee34ebdf88 100644
--- a/nixos/modules/services/monitoring/datadog-agent.nix
+++ b/nixos/modules/services/monitoring/datadog-agent.nix
@@ -38,6 +38,12 @@ let
     target = "datadog-agent/datadog.yaml";
   }] ++ makeCheckConfigs (cfg.checks // defaultChecks);
 
+  # Apply the configured extraIntegrations to the provided agent
+  # package. See the documentation of `dd-agent/integrations-core.nix`
+  # for detailed information on this.
+  datadogPkg = cfg.package.overrideAttrs(_: {
+    python = (pkgs.datadog-integrations-core cfg.extraIntegrations).python;
+  });
 in {
   options.services.datadog-agent = {
     enable = mkOption {
@@ -52,9 +58,10 @@ in {
       default = pkgs.datadog-agent;
       defaultText = "pkgs.datadog-agent";
       description = ''
-        Which DataDog v6 agent package to use.
-        Override the <literal>pythonPackages</literal> argument
-        of this derivation to include more checks.
+        Which DataDog v6 agent package to use. Note that the provided
+        package is expected to have an overridable `python`-attribute
+        which configures the Python environment with the Datadog
+        checks.
       '';
       type = types.package;
     };
@@ -88,6 +95,27 @@ in {
       type = types.nullOr (types.enum ["DEBUG" "INFO" "WARN" "ERROR"]);
     };
 
+    extraIntegrations = mkOption {
+      default = {};
+      type    = types.attrs;
+
+      description = ''
+        Extra integrations from the Datadog core-integrations
+        repository that should be built and included.
+
+        By default the included integrations are disk, mongo, network,
+        nginx and postgres.
+
+        To include additional integrations the name of the derivation
+        and a function to filter its dependencies from the Python
+        package set must be provided.
+      '';
+
+      example = {
+        ntp = (pythonPackages: [ pythonPackages.ntplib ]);
+      };
+    };
+
     extraConfig = mkOption {
       default = {};
       type = types.attrs;
@@ -157,7 +185,7 @@ in {
     };
   };
   config = mkIf cfg.enable {
-    environment.systemPackages = [ cfg.package pkgs.sysstat pkgs.procps ];
+    environment.systemPackages = [ datadogPkg pkgs.sysstat pkgs.procps ];
 
     users.extraUsers.datadog = {
       description = "Datadog Agent User";
@@ -171,7 +199,7 @@ in {
 
     systemd.services = let
       makeService = attrs: recursiveUpdate {
-        path = [ cfg.package pkgs.python pkgs.sysstat pkgs.procps ];
+        path = [ datadogPkg pkgs.python pkgs.sysstat pkgs.procps ];
         wantedBy = [ "multi-user.target" ];
         serviceConfig = {
           User = "datadog";
@@ -180,7 +208,7 @@ in {
           RestartSec = 2;
           PrivateTmp = true;
         };
-        restartTriggers = [ cfg.package ] ++ map (etc: etc.source) etcfiles;
+        restartTriggers = [ datadogPkg ] ++ map (etc: etc.source) etcfiles;
       } attrs;
     in {
       datadog-agent = makeService {
@@ -190,16 +218,16 @@ in {
           rm -f /etc/datadog-agent/auth_token
         '';
         script = ''
-          export DD_API_KEY=$(head -n1 ${cfg.apiKeyFile})
-          exec ${cfg.package}/bin/agent start -c /etc/datadog-agent/datadog.yaml
+          export DD_API_KEY=$(head -n 1 ${cfg.apiKeyFile})
+          exec ${datadogPkg}/bin/agent start -c /etc/datadog-agent/datadog.yaml
         '';
         serviceConfig.PermissionsStartOnly = true;
       };
 
       dd-jmxfetch = lib.mkIf (lib.hasAttr "jmx" cfg.checks) (makeService {
         description = "Datadog JMX Fetcher";
-        path = [ cfg.package pkgs.python pkgs.sysstat pkgs.procps pkgs.jdk ];
-        serviceConfig.ExecStart = "${cfg.package}/bin/dd-jmxfetch";
+        path = [ datadogPkg pkgs.python pkgs.sysstat pkgs.procps pkgs.jdk ];
+        serviceConfig.ExecStart = "${datadogPkg}/bin/dd-jmxfetch";
       });
     };