forked from DataDog/chef-datadog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatadog.yaml.erb
183 lines (159 loc) · 6.2 KB
/
datadog.yaml.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<%
# OPTIONS REMOVED IN AGENT 6:
# - check_freq
# - use_mount
# - developer_mode
# - dogstreams
# - autorestart
# - custom_emitters
# - graphite
# - dogstatsd_target
# - dogstatsd_interval
# - dogstatsd_normalize
# - legacy_integrations
# - listen_port (`agent_port` attribute)
# TODO: options not supported yet:
# - agent_checks_interval
# - Autodiscovery (aka Service Discovery) related options
def string_list_to_array(string_list)
# return an array from a comma-separated list in a string
string_list.split(',').map{ |elem| elem.strip }
end
## Normalize complex config values for agent6 format ##
if node['datadog']['tags'].respond_to?(:each_pair)
tags = node['datadog']['tags'].reject{ |_k,v| v.empty? }.map{ |k,v| "#{k.strip}:#{v.strip}" }
elsif node['datadog']['tags'].respond_to?(:each)
tags = node['datadog']['tags']
else
tags = string_list_to_array(node['datadog']['tags'])
end
# TODO: support the more complete proxy settings that the agent6 supports
http_proxy = nil
no_proxy = nil
if node['datadog']['web_proxy']['host']
host = node['datadog']['web_proxy']['host']
port = node['datadog']['web_proxy']['port']
user = node['datadog']['web_proxy']['user']
password = node['datadog']['web_proxy']['password']
scheme = ""
no_proxy = node['datadog']['web_proxy']['no_proxy']
unless host.start_with?('http://') or host.start_with?('https://')
scheme = 'http://'
end
http_proxy = host
if port
http_proxy += ":#{port}"
end
if user
if password
http_proxy = "#{user}:#{password}@#{http_proxy}"
else
http_proxy = "#{user}@#{http_proxy}"
end
end
http_proxy = scheme + http_proxy
end
# In the default case we will start and run with only container collection.
process_agent_enabled = 'false'
if node['datadog']['enable_process_agent'].is_a?(TrueClass)
# Collect processes if enabled.
process_agent_enabled = 'true'
elsif node['datadog']['enable_process_agent'].is_a?(FalseClass)
# Disable the Agent altogether if false.
process_agent_enabled = 'disabled'
end
## Populate agent_config ##
agent_config = @extra_config.merge({
api_key: @api_key,
site: node['datadog']['site'],
dd_url: node['datadog']['url'],
hostname: node['datadog']['hostname'],
bind_host: node['datadog']['bind_host'],
additional_endpoints: @additional_endpoints,
skip_ssl_validation: node['datadog']['web_proxy']['skip_ssl_validation'],
tags: tags,
env: node['datadog']['env'],
create_dd_check_tags: node['datadog']['create_dd_check_tags'],
collect_ec2_tags: node['datadog']['collect_ec2_tags'],
dogstatsd_non_local_traffic: node['datadog']['non_local_traffic'],
histogram_aggregates: string_list_to_array(node['datadog']['histogram_aggregates']),
histogram_percentiles: string_list_to_array(node['datadog']['histogram_percentiles']),
use_dogstatsd: node['datadog']['dogstatsd'],
statsd_metric_namespace: node['datadog']['statsd_metric_namespace'],
log_level: node['datadog']['log_level'],
cmd_port: node['datadog']['cmd_port'],
GUI_port: node['datadog']['gui_port'],
# log agent options
logs_enabled: node['datadog']['enable_logs_agent'],
})
if node['datadog']['statsd_forward_host']
# TODO: in next major, make `nil` the default value of `statsd_forward_port` to normalize handling
agent_config['statsd_forward_host'] = node['datadog']['statsd_forward_host']
agent_config['statsd_forward_port'] = node['datadog']['statsd_forward_port']
end
if node['datadog']['logs_agent_config']
agent_config['logs_config'] = node['datadog']['logs_agent_config']
end
if node['datadog']['log_file_directory']
agent_config['log_file'] = ::File.join(node['datadog']['log_file_directory'], "agent.log")
end
if !node['datadog']['use_v2_api'].nil? && !node['datadog']['use_v2_api'].empty?
agent_config['use_v2_api'] = node['datadog']['use_v2_api']
end
if node['datadog']['syslog']['active']
agent_config['log_to_syslog'] = true
# TODO: double check the udp settings work with agent6
if node['datadog']['syslog']['udp']
agent_config['syslog_uri'] = "#{node['datadog']['syslog']['host']}:#{node['datadog']['syslog']['port']}"
end
end
if !node['datadog']['log_to_console'].nil?
agent_config['log_to_console'] = node['datadog']['log_to_console']
end
# Set proxy options
if !http_proxy.nil?
agent_config['proxy'] = {
http: http_proxy,
https: http_proxy
}
agent_config['proxy']['no_proxy'] = no_proxy if !no_proxy.nil?
end
## Process agent options ##
process_config = {
enabled: process_agent_enabled,
log_file: node['datadog']['process_agent']['log_file'],
intervals: {
container: node['datadog']['process_agent']['container_interval'],
container_realtime: node['datadog']['process_agent']['rtcontainer_interval'],
process: node['datadog']['process_agent']['process_interval'],
process_realtime: node['datadog']['process_agent']['rtprocess_interval'],
},
blacklist_patterns: node['datadog']['process_agent']['blacklist'],
scrub_args: node['datadog']['process_agent']['scrub_args'],
custom_sensitive_words: node['datadog']['process_agent']['custom_sensitive_words'],
process_dd_url: node['datadog']['process_agent']['url']
}
# Take into account options defined under ['extra_config']['process_config']
process_config = @extra_config['process_config'].merge(process_config) unless @extra_config['process_config'].nil?
agent_config[:process_config] = process_config
# Remove nil values
agent_config[:process_config][:intervals].reject!{ |k,v| v.nil? }
agent_config[:process_config].reject!{ |k,v| v.nil? }
## Trace agent options ##
apm_config = {
enabled: node['datadog']['enable_trace_agent'],
env: node['datadog']['trace_env'],
extra_sample_rate: node['datadog']['extra_sample_rate'],
max_traces_per_second: node['datadog']['max_traces_per_second'],
receiver_port: node['datadog']['receiver_port'],
apm_non_local_traffic: node['datadog']['non_local_traffic']
}
apm_config.reject!{ |k,v| v.nil? }
# Take into account options defined under ['extra_config']['apm_config']
apm_config = @extra_config['apm_config'].merge(apm_config) unless @extra_config['apm_config'].nil?
agent_config[:apm_config] = apm_config
# Remove nil values
agent_config.reject!{ |k,v| v.nil? }
-%>
# Generated by Chef, local modifications will be overwritten
<%= JSON.parse(agent_config.to_json).to_yaml %>