Skip to content

Commit 6fb680d

Browse files
authored
Merge pull request DataDog#378 from flyinprogrammer/master
parameterize docker_daemon.yaml
2 parents e04b337 + 8e716ea commit 6fb680d

3 files changed

Lines changed: 123 additions & 32 deletions

File tree

manifests/integrations/docker_daemon.pp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,40 @@
2020
# }
2121
#
2222
class datadog_agent::integrations::docker_daemon(
23+
$group = 'docker',
24+
$docker_root = '/',
25+
$timeout = 10,
26+
$api_version = 'auto',
27+
$tls = false,
28+
$tls_client_cert = '/path/to/client-cert.pem',
29+
$tls_client_key = '/path/to/client-key.pem',
30+
$tls_cacert = '/path/to/ca.pem',
31+
$tls_verify = true,
32+
$init_retry_interval = 0,
33+
$init_retries = 0,
2334
$url = 'unix://var/run/docker.sock',
35+
$collect_events = true,
36+
$filtered_event_types = [],
37+
$collect_container_size = false,
38+
$custom_cgroups = false,
39+
$health_service_check_whitelist = [],
40+
$collect_container_count = false,
41+
$collect_volume_count = false,
42+
$collect_images_stats = false,
43+
$collect_image_size = false,
44+
$collect_disk_stats = false,
45+
$collect_exit_codes = false,
46+
$exclude = [],
47+
$include = [],
2448
$tags = [],
25-
$group = 'docker',
49+
$ecs_tags = true,
50+
# Possible values: "container_name", "image_name", "image_tag", "docker_image"
51+
$performance_tags = [],
52+
# Possible values: "image_name", "image_tag", "docker_image"
53+
$container_tags = [],
54+
# Ex. "com.docker.compose.service", "com.docker.compose.project"
55+
$collect_labels_as_tags = [],
56+
$event_attributes_as_tags = [],
2657
) inherits datadog_agent::params {
2758
include datadog_agent
2859

spec/classes/datadog_agent_integrations_docker_daemon_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
let(:params) {{
4848
tags: %w{ foo bar baz },
4949
}}
50-
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
50+
it { should contain_file(conf_file).with_content(%r{tags: \["foo", "bar", "baz"\]}) }
5151
end
5252

5353
context 'with tags parameter with an empty tag' do
@@ -59,23 +59,23 @@
5959
tags: [ 'foo', '', 'baz' ]
6060
}}
6161

62-
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
62+
it { should contain_file(conf_file).with_content(%r{tags: \["foo", "baz"\]}) }
6363
end
6464

6565
context 'single element array of an empty string' do
6666
let(:params) {{
6767
tags: [''],
6868
}}
6969

70-
skip("undefined behavior")
70+
it { should contain_file(conf_file).with_content(%r{tags: \[\]}) }
7171
end
7272

7373
context 'single value empty string' do
7474
let(:params) {{
7575
tags: '',
7676
}}
7777

78-
skip("doubly undefined behavior")
78+
it { should contain_file(conf_file).with_content(%r{tags: \[\]}) }
7979
end
8080
end
8181
end

templates/agent-conf.d/docker_daemon.yaml.erb

Lines changed: 87 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,39 @@ init_config:
22
# Change the root directory to look at to get cgroup statistics. Useful when running inside a
33
# container with host directories mounted on a different folder. Default: /.
44
# Example for the docker-dd-agent container:
5-
# docker_root: /host
5+
docker_root: <%= @docker_root %>
66

77
# Timeout in seconds for the connection to the docker daemon
88
# Default: 5 seconds
99
#
10-
# timeout: 10
10+
timeout: <%= @timeout %>
1111

1212
# The version of the API the client will use. Specify 'auto' to use the API version provided by the server.
13-
# api_version: auto
13+
api_version: <%= @api_version %>
1414

1515
# Use TLS encryption while communicating with the Docker API
1616
#
17-
# tls: False
18-
# tls_client_cert: /path/to/client-cert.pem
19-
# tls_client_key: /path/to/client-key.pem
20-
# tls_cacert: /path/to/ca.pem
21-
# tls_verify: True
17+
tls: <%= @tls %>
18+
tls_client_cert: <%= @tls_client_cert %>
19+
tls_client_key: <%= @tls_client_key %>
20+
tls_cacert: <%= @tls_cacert %>
21+
tls_verify: <%= @tls_verify %>
22+
23+
# Initialization retries
24+
#
25+
# if the agent is expected to start before Docker,
26+
# use these settings to configure the retry policy.
27+
28+
# init_retry_interval defines how long (in seconds) the docker client
29+
# will wait before retrying initialization.
30+
# Defaults to 0.
31+
#
32+
init_retry_interval: <%= @init_retry_interval %>
33+
34+
# init_retries configures how many retries are made before failing permanently.
35+
# Defaults to 0.
36+
#
37+
init_retries: <%= @init_retries %>
2238

2339
instances:
2440
- ## Daemon and system configuration
@@ -35,29 +51,76 @@ instances:
3551
# Create events whenever a container status change.
3652
# Defaults to true.
3753
#
38-
# collect_events: false
54+
collect_events: <%= @collect_events %>
55+
56+
# By default we do not collect events with a status ['top', 'exec_start', 'exec_create'].
57+
# Here can be added additional statuses to be filtered.
58+
# List of available statuses can be found here https://docs.docker.com/engine/reference/commandline/events/#object-types
59+
filtered_event_types: [<%= @filtered_event_types && !@filtered_event_types.empty? ? '"' + @filtered_event_types.reject(&:empty?).join('", "') + '"' : nil %>]
3960

4061
# Collect disk usage per container with docker.container.size_rw and
4162
# docker.container.size_rootfs metrics.
4263
# Warning: This might take time for Docker daemon to generate,
4364
# ensure that `docker ps -a -q` run fast before enabling it.
4465
# Defaults to false.
4566
#
46-
# collect_container_size: false
67+
collect_container_size: <%= @collect_container_size %>
68+
69+
# Do you use custom cgroups for this particular instance?
70+
# Note: enabling this option modifies the way in which we inspect the containers and causes
71+
# some overhead - if you run a high volume of containers we may timeout.
72+
#
73+
custom_cgroups: <%= @custom_cgroups %>
74+
75+
# Report docker container healthcheck events as service checks
76+
# Note: enabling this option modifies the way in which we inspect the containers and causes
77+
# some overhead - if you run a high volume of containers we may timeout.
78+
# Container Healthchecks are available starting with docker 1.12, enabling with older
79+
# versions will result in an UNKNOWN state for the service check.
80+
#
81+
# You must whitelist the containers you wish to submit health service checks for.
82+
# Use the same mechanism as the tagging system (see Tag:performance_tags section).
83+
# Example: ["docker_image:tomcat", "container_name:web_front_nginx"]
84+
#
85+
health_service_check_whitelist: [<%= @health_service_check_whitelist && !@health_service_check_whitelist.empty? ? '"' + @health_service_check_whitelist.reject(&:empty?).join('", "') + '"' : nil %>]
86+
87+
# Collect the container count tagged by state (running, paused, exited, dead)
88+
# Defaults to false.
89+
#
90+
collect_container_count: <%= @collect_container_count %>
91+
92+
# Collect the volume count for attached and dangling volumes.
93+
# Defaults to false.
94+
#
95+
collect_volume_count: <%= @collect_volume_count %>
4796

4897
# Collect images stats
4998
# Number of available active images and intermediate images as gauges.
5099
# Defaults to false.
51100
#
52-
# collect_images_stats: false
101+
collect_images_stats: <%= @collect_images_stats %>
53102

54103
# Collect disk usage per image with docker.image.size and docker.image.virtual_size metrics.
55104
# The check gets this size with the `docker images` command.
56105
# Requires collect_images_stats to be enabled.
57106
# Defaults to false.
58107
#
59-
# collect_image_size: false
108+
collect_image_size: <%= @collect_image_size %>
109+
110+
# Collect disk metrics (total, used, free) through the docker info command for data and metadata.
111+
# This is useful when these values can't be obtained by the disk check.
112+
# Example: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html
113+
# Note that it only works when the storage driver is devicemapper.
114+
# Explanation of these metrics can be found here:
115+
# https://github.com/docker/docker/blob/v1.11.1/daemon/graphdriver/devmapper/README.md
116+
# Defaults to false.
117+
#
118+
collect_disk_stats: <%= @collect_disk_stats %>
60119

120+
# Collect containers exit codes and send service checks critical when exit code is not 0
121+
# Defaults to false.
122+
#
123+
collect_exit_codes: <%= @collect_exit_codes %>
61124

62125
# Exclude containers based on their tags
63126
# An excluded container will be completely ignored. The rule is a regex on the tags.
@@ -75,28 +138,20 @@ instances:
75138
#
76139
# Default: include all containers
77140

78-
141+
exclude: [<%= @exclude && !@exclude.empty? ? '"' + @exclude.reject(&:empty?).join('", "') + '"' : nil %>]
142+
include: [<%= @include && !@include.empty? ? '"' + @include.reject(&:empty?).join('", "') + '"' : nil %>]
79143

80144
## Tagging
81145
##
82-
<% if @tags and ! @tags.empty? -%>
83-
tags:
84-
<%- Array(@tags).each do |tag| -%>
85-
<%- if tag != '' -%>
86-
- <%= tag %>
87-
<%- end -%>
88-
<%- end -%>
89-
<% end -%>
90-
91146
# You can add extra tags to your Docker metrics with the tags list option.
92147
# Example: ["extra_tag", "env:testing"]
93148
#
94-
# tags: []
149+
tags: [<%= @tags && !@tags.empty? ? '"' + @tags.reject(&:empty?).join('", "') + '"' : nil %>]
95150

96151
# If the agent is running in an Amazon ECS task, tags container metrics with the ECS task name and version.
97152
# Default: true
98153
#
99-
# ecs_tags: false
154+
ecs_tags: <%= @ecs_tags %>
100155

101156
# Custom metrics tagging
102157
# Define which Docker tags to apply on metrics.
@@ -110,14 +165,19 @@ instances:
110165
# - container_name: Name of the container (example: "boring_euclid")
111166
# - container_command: Command ran by the container (example: "echo 1")
112167
#
113-
# performance_tags: ["container_name", image_name", "image_tag", "docker_image"]
168+
performance_tags: [<%= @performance_tags && !@performance_tags.empty? ? '"' + @performance_tags.reject(&:empty?).join('", "') + '"' : nil %>]
114169

115170
# Tags for containers count metrics.
116171
# Available: ["image_name", "image_tag", "docker_image", "container_command"]
117172
#
118-
# container_tags: ["image_name", "image_tag", "docker_image"]
173+
container_tags: [<%= @container_tags && !@container_tags.empty? ? '"' + @container_tags.reject(&:empty?).join('", "') + '"' : nil %>]
119174

120175
# List of container label names that should be collected and sent as tags.
121176
# Default to None
122177
# Example:
123-
# collect_labels_as_tags: ["com.docker.compose.service", "com.docker.compose.project"]
178+
collect_labels_as_tags: [<%= @collect_labels_as_tags && !@collect_labels_as_tags.empty? ? '"' + @collect_labels_as_tags.reject(&:empty?).join('", "') + '"' : nil %>]
179+
180+
# List of docker event attributes to add as tags of the datadog events
181+
# Defaults to None.
182+
#
183+
event_attributes_as_tags: [<%= @event_attributes_as_tags && !@event_attributes_as_tags.empty? ? '"' + @event_attributes_as_tags.reject(&:empty?).join('", "') + '"' : nil %>]

0 commit comments

Comments
 (0)