at 18.09-beta 7.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.dd-agent; 7 8 ddConf = pkgs.writeText "datadog.conf" '' 9 [Main] 10 dd_url: https://app.datadoghq.com 11 skip_ssl_validation: no 12 api_key: ${cfg.api_key} 13 ${optionalString (cfg.hostname != null) "hostname: ${cfg.hostname}"} 14 15 collector_log_file: /var/log/datadog/collector.log 16 forwarder_log_file: /var/log/datadog/forwarder.log 17 dogstatsd_log_file: /var/log/datadog/dogstatsd.log 18 pup_log_file: /var/log/datadog/pup.log 19 20 # proxy_host: my-proxy.com 21 # proxy_port: 3128 22 # proxy_user: user 23 # proxy_password: password 24 25 # tags: mytag0, mytag1 26 ${optionalString (cfg.tags != null ) "tags: ${concatStringsSep ", " cfg.tags }"} 27 28 # collect_ec2_tags: no 29 # recent_point_threshold: 30 30 # use_mount: no 31 # listen_port: 17123 32 # graphite_listen_port: 17124 33 # non_local_traffic: no 34 # use_curl_http_client: False 35 # bind_host: localhost 36 37 # use_pup: no 38 # pup_port: 17125 39 # pup_interface: localhost 40 # pup_url: http://localhost:17125 41 42 # dogstatsd_port : 8125 43 # dogstatsd_interval : 10 44 # dogstatsd_normalize : yes 45 # statsd_forward_host: address_of_own_statsd_server 46 # statsd_forward_port: 8125 47 48 # device_blacklist_re: .*\/dev\/mapper\/lxc-box.* 49 50 # ganglia_host: localhost 51 # ganglia_port: 8651 52 ''; 53 54 diskConfig = pkgs.writeText "disk.yaml" '' 55 init_config: 56 57 instances: 58 - use_mount: no 59 ''; 60 61 networkConfig = pkgs.writeText "network.yaml" '' 62 init_config: 63 64 instances: 65 # Network check only supports one configured instance 66 - collect_connection_state: false 67 excluded_interfaces: 68 - lo 69 - lo0 70 ''; 71 72 postgresqlConfig = pkgs.writeText "postgres.yaml" cfg.postgresqlConfig; 73 nginxConfig = pkgs.writeText "nginx.yaml" cfg.nginxConfig; 74 mongoConfig = pkgs.writeText "mongo.yaml" cfg.mongoConfig; 75 jmxConfig = pkgs.writeText "jmx.yaml" cfg.jmxConfig; 76 processConfig = pkgs.writeText "process.yaml" cfg.processConfig; 77 78 etcfiles = 79 let 80 defaultConfd = import ./dd-agent-defaults.nix; 81 in (map (f: { source = "${pkgs.dd-agent}/agent/conf.d-system/${f}"; 82 target = "dd-agent/conf.d/${f}"; 83 }) defaultConfd) ++ [ 84 { source = ddConf; 85 target = "dd-agent/datadog.conf"; 86 } 87 { source = diskConfig; 88 target = "dd-agent/conf.d/disk.yaml"; 89 } 90 { source = networkConfig; 91 target = "dd-agent/conf.d/network.yaml"; 92 } ] ++ 93 (optional (cfg.postgresqlConfig != null) 94 { source = postgresqlConfig; 95 target = "dd-agent/conf.d/postgres.yaml"; 96 }) ++ 97 (optional (cfg.nginxConfig != null) 98 { source = nginxConfig; 99 target = "dd-agent/conf.d/nginx.yaml"; 100 }) ++ 101 (optional (cfg.mongoConfig != null) 102 { source = mongoConfig; 103 target = "dd-agent/conf.d/mongo.yaml"; 104 }) ++ 105 (optional (cfg.processConfig != null) 106 { source = processConfig; 107 target = "dd-agent/conf.d/process.yaml"; 108 }) ++ 109 (optional (cfg.jmxConfig != null) 110 { source = jmxConfig; 111 target = "dd-agent/conf.d/jmx.yaml"; 112 }); 113 114in { 115 options.services.dd-agent = { 116 enable = mkOption { 117 description = '' 118 Whether to enable the dd-agent v5 monitoring service. 119 For datadog-agent v6, see <option>services.datadog-agent.enable</option>. 120 ''; 121 default = false; 122 type = types.bool; 123 }; 124 125 api_key = mkOption { 126 description = '' 127 The Datadog API key to associate the agent with your account. 128 129 Warning: this key is stored in cleartext within the world-readable 130 Nix store! Consider using the new v6 131 <option>services.datadog-agent</option> module instead. 132 ''; 133 example = "ae0aa6a8f08efa988ba0a17578f009ab"; 134 type = types.str; 135 }; 136 137 tags = mkOption { 138 description = "The tags to mark this Datadog agent"; 139 example = [ "test" "service" ]; 140 default = null; 141 type = types.nullOr (types.listOf types.str); 142 }; 143 144 hostname = mkOption { 145 description = "The hostname to show in the Datadog dashboard (optional)"; 146 default = null; 147 example = "mymachine.mydomain"; 148 type = types.uniq (types.nullOr types.string); 149 }; 150 151 postgresqlConfig = mkOption { 152 description = "Datadog PostgreSQL integration configuration"; 153 default = null; 154 type = types.uniq (types.nullOr types.string); 155 }; 156 157 nginxConfig = mkOption { 158 description = "Datadog nginx integration configuration"; 159 default = null; 160 type = types.uniq (types.nullOr types.string); 161 }; 162 163 mongoConfig = mkOption { 164 description = "MongoDB integration configuration"; 165 default = null; 166 type = types.uniq (types.nullOr types.string); 167 }; 168 169 jmxConfig = mkOption { 170 description = "JMX integration configuration"; 171 default = null; 172 type = types.uniq (types.nullOr types.string); 173 }; 174 175 processConfig = mkOption { 176 description = '' 177 Process integration configuration 178 179 See http://docs.datadoghq.com/integrations/process/ 180 ''; 181 default = null; 182 type = types.uniq (types.nullOr types.string); 183 }; 184 185 }; 186 187 config = mkIf cfg.enable { 188 environment.systemPackages = [ pkgs."dd-agent" pkgs.sysstat pkgs.procps ]; 189 190 users.users.datadog = { 191 description = "Datadog Agent User"; 192 uid = config.ids.uids.datadog; 193 group = "datadog"; 194 home = "/var/log/datadog/"; 195 createHome = true; 196 }; 197 198 users.groups.datadog.gid = config.ids.gids.datadog; 199 200 systemd.services = let 201 makeService = attrs: recursiveUpdate { 202 path = [ pkgs.dd-agent pkgs.python pkgs.sysstat pkgs.procps pkgs.gohai ]; 203 wantedBy = [ "multi-user.target" ]; 204 serviceConfig = { 205 User = "datadog"; 206 Group = "datadog"; 207 Restart = "always"; 208 RestartSec = 2; 209 PrivateTmp = true; 210 }; 211 restartTriggers = [ pkgs.dd-agent ddConf diskConfig networkConfig postgresqlConfig nginxConfig mongoConfig jmxConfig processConfig ]; 212 } attrs; 213 in { 214 dd-agent = makeService { 215 description = "Datadog agent monitor"; 216 serviceConfig.ExecStart = "${pkgs.dd-agent}/bin/dd-agent foreground"; 217 }; 218 219 dogstatsd = makeService { 220 description = "Datadog statsd"; 221 environment.TMPDIR = "/run/dogstatsd"; 222 serviceConfig = { 223 ExecStart = "${pkgs.dd-agent}/bin/dogstatsd start"; 224 Type = "forking"; 225 PIDFile = "/run/dogstatsd/dogstatsd.pid"; 226 RuntimeDirectory = "dogstatsd"; 227 }; 228 }; 229 230 dd-jmxfetch = lib.mkIf (cfg.jmxConfig != null) { 231 description = "Datadog JMX Fetcher"; 232 path = [ pkgs.dd-agent pkgs.python pkgs.sysstat pkgs.procps pkgs.jdk ]; 233 serviceConfig.ExecStart = "${pkgs.dd-agent}/bin/dd-jmxfetch"; 234 }; 235 }; 236 237 environment.etc = etcfiles; 238 }; 239}