Skip to content

Commit ccf287c

Browse files
jensendwtruthbk
authored andcommitted
Support mongodb collection metrics per collection (DataDog#335)
* Support mongodb collection metrics per collection * spec tests and example for mongo collections/additional_metrics
1 parent d091cc9 commit ccf287c

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

manifests/integrations/mongo.pp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
# 'username' => 'mongo_username',
4848
# },
4949
# {
50-
# 'host' => 'localhost',
51-
# 'port' => '27018',
52-
# 'tags' => [],
50+
# 'host' => 'localhost',
51+
# 'port' => '27018',
52+
# 'tags' => [],
53+
# 'additional_metrics' => [],
54+
# 'collections' => [],
5355
# },
5456
# ]
5557
# }

spec/classes/datadog_agent_integrations_mongo_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,59 @@
5959
it { should contain_file(conf_file).with_content(%r{server:.*127.0.0.1.*server:.*127.0.0.2}m) }
6060
end
6161

62+
context 'with custom collections one mongos' do
63+
let(:params) {{
64+
servers: [
65+
{
66+
'host' => '127.0.0.1',
67+
'port' => '12345',
68+
'tags' => %w{ foo bar baz },
69+
'collections' => %w{ collection_1 collection_2 },
70+
},
71+
{
72+
'host' => '127.0.0.2',
73+
'port' => '45678',
74+
'tags' => %w{baz bat},
75+
'collections' => %w{ collection_1 collection_2 },
76+
}
77+
]
78+
}}
79+
80+
it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) }
81+
it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.2:45678/\s+tags:\s+- baz\s+- bat\s+collections:\s+- collection_1\s+- collection_2}) }
82+
83+
end
84+
85+
context 'with custom collections multiple mongo' do
86+
let(:params) {{
87+
servers: [
88+
{
89+
'host' => '127.0.0.1',
90+
'port' => '12345',
91+
'tags' => %w{ foo bar baz },
92+
'collections' => %w{ collection_1 collection_2 },
93+
}
94+
]
95+
}}
96+
97+
it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) }
98+
end
99+
100+
context 'with additional metrics' do
101+
let(:params) {{
102+
servers: [
103+
{
104+
'host' => '127.0.0.1',
105+
'port' => '12345',
106+
'tags' => %w{ foo bar baz },
107+
'additional_metrics' => %w{ top },
108+
}
109+
]
110+
}}
111+
112+
it { should contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+additional_metrics:\s+- top}) }
113+
end
114+
62115
context 'without tags' do
63116
let(:params) {{
64117
servers: [

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ instances:
3434
- <%= additional_metric %>
3535
<%- end -%>
3636
<%- end -%>
37+
<%- if !server['collections'].nil? && server['collections'].any? -%>
38+
collections:
39+
<%- server['collections'].each do |collection| -%>
40+
- <%= collection %>
41+
<%- end -%>
42+
<%- end -%>
3743
<% end -%>

0 commit comments

Comments
 (0)