Skip to content

Commit 2fc5abd

Browse files
committed
Add support for the JMX integration
1 parent 8218721 commit 2fc5abd

3 files changed

Lines changed: 187 additions & 0 deletions

File tree

manifests/integrations/jmx.pp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Class: datadog_agent::integrations::jmx
2+
#
3+
# This class will install the necessary configuration for the jmx integration
4+
#
5+
# Parameters:
6+
# $init_config:
7+
# Hash of inital configuration, consisting of the following keys:
8+
#
9+
# custom_jar_paths:
10+
# Array of paths to jars. Optional.
11+
#
12+
# $instances:
13+
# Array of instance hashes, consisting of the following keys:
14+
#
15+
# name:
16+
# Used in conjunction with jmx_url. Optional.
17+
# tags:
18+
# Hash of tags { 'env' => 'prod' }. Optional.
19+
# host:
20+
# The host jmx is running on.
21+
# port:
22+
# The JMX port.
23+
# jmx_url:
24+
# If the agent needs to connect to a non-default JMX URL, specify it here
25+
# instead of a host and a port. If you use this you need to specify a ‘name’
26+
# for the instance. Optional.
27+
# user:
28+
# The username for connecting to the running JVM. Optional.
29+
# password:
30+
# The password for connecting to the running JVM. Optional.
31+
# process_name_regex:
32+
# Instead of specifying a host and port or jmx_url, the agent can
33+
# connect using the attach api. This requires the JDK to be installed
34+
# and the path to tools.jar to be set. Optional.
35+
# tools_jar_path:
36+
# To be set when process_name_regex is set. Optional.
37+
# java_bin_path:
38+
# The path to the Java binary. Should be set if the agent cannot find your java executable. Optional.
39+
# java_options:
40+
# Java JVM options. Optional.
41+
# trust_store_path:
42+
# The path to the trust store. Should be set if ssl is enabled. Optional.
43+
# trust_store_password:
44+
# The trust store password. Should be set if ssl is enabled. Optional.
45+
# conf:
46+
# Array of include/exclude hash pairs. Optional.
47+
# Read http://docs.datadoghq.com/integrations/java/ to learn how to customize it.
48+
#
49+
# Sample Usage:
50+
#
51+
# class { 'datadog_agent::integrations::jmx':
52+
# init_config => {
53+
# custom_jar_paths => ['/path/to/custom.jar']
54+
# },
55+
# instances => [{
56+
# host => 'localhost',
57+
# port => 7199,
58+
# user => 'username',
59+
# password => 'password',
60+
# jmx_url => 'service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath'
61+
# }],
62+
# }
63+
#
64+
class datadog_agent::integrations::jmx(
65+
$init_config = {},
66+
$instances = [],
67+
) inherits datadog_agent::params {
68+
include datadog_agent
69+
70+
file { "${datadog_agent::params::conf_dir}/jmx.yaml":
71+
ensure => file,
72+
owner => $datadog_agent::params::dd_user,
73+
group => $datadog_agent::params::dd_group,
74+
mode => '0600',
75+
content => template('datadog_agent/agent-conf.d/jmx.yaml.erb'),
76+
require => Package[$datadog_agent::params::package_name],
77+
notify => Service[$datadog_agent::params::service_name]
78+
}
79+
80+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
require 'spec_helper'
2+
3+
describe 'datadog_agent::integrations::jmx' do
4+
let(:facts) {{
5+
operatingsystem: 'Ubuntu',
6+
}}
7+
let(:conf_dir) { '/etc/dd-agent/conf.d' }
8+
let(:dd_user) { 'dd-agent' }
9+
let(:dd_group) { 'root' }
10+
let(:dd_package) { 'datadog-agent' }
11+
let(:dd_service) { 'datadog-agent' }
12+
let(:conf_file) { "#{conf_dir}/jmx.yaml" }
13+
14+
it { should compile.with_all_deps }
15+
it { should contain_file(conf_file).with(
16+
owner: dd_user,
17+
group: dd_group,
18+
mode: '0600',
19+
)}
20+
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
21+
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }
22+
23+
context 'with default parameters' do
24+
it { should contain_file(conf_file).with_content(%r{init_config: \{\}}) }
25+
it { should contain_file(conf_file).with_content(%r{instances: \[\]}) }
26+
end
27+
28+
context 'with parameters set' do
29+
let(:params) do
30+
{
31+
'init_config' => {
32+
'custom_jar_paths' => [
33+
'/path/to/custom/jarfile.jar',
34+
'/path/to/another/custom/jarfile2.jar'
35+
]
36+
},
37+
'instances' => [{
38+
'host' => 'jmx1',
39+
'port' => '867',
40+
'user' => 'userfoo',
41+
'password' => 'passbar',
42+
'jmx_url' => 'service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath',
43+
'tools_jar_path' => '/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar',
44+
'java_options' => '-Xmx200m -Xms50m',
45+
'java_bin_path' => '/usr/java/jdk1.7.0_101/bin/java',
46+
'trust_store_path' => '/var/lib/jmx/trust_store_path',
47+
'trust_store_password' => 'hunter2',
48+
'tags' => {
49+
'foo' => 'bar',
50+
'baz' => 'bat'
51+
},
52+
'conf' => [{
53+
'include' => {
54+
'domain' => 'my_domain'
55+
}
56+
}]
57+
}]
58+
}
59+
end
60+
it { should contain_file(conf_file).with_content(%r{- /path/to/custom/jarfile.jar}) }
61+
it { should contain_file(conf_file).with_content(%r{- /path/to/another/custom/jarfile2.jar}) }
62+
it { should contain_file(conf_file).with_content(%r{host: jmx1}) }
63+
64+
# Stringification of integers.
65+
# Puppet treats everything as a string, and then there seems to be
66+
# quoting differences between YAML export deps for Puppet 3.x and Puppet 4.x.
67+
# YAML defaults to string representation, but supports other types, so ends
68+
# up quoting integers from Puppet to explicitly mark out they're strings.
69+
it { should contain_file(conf_file).with_content(%r{port: ["']?867["']?}) }
70+
71+
it { should contain_file(conf_file).with_content(%r{jmx_url: ["']?service:jmx:rmi:///jndi/rmi://myhost.host:9999/custompath["']?}) }
72+
it { should contain_file(conf_file).with_content(%r{user: userfoo}) }
73+
it { should contain_file(conf_file).with_content(%r{password: passbar}) }
74+
it { should contain_file(conf_file).with_content(%r{java_bin_path: /usr/java/jdk1.7.0_101/bin/java}) }
75+
it { should contain_file(conf_file).with_content(%r{java_options: ["']?-Xmx200m -Xms50m["']?}) }
76+
it { should contain_file(conf_file).with_content(%r{trust_store_path: /var/lib/jmx/trust_store_path}) }
77+
it { should contain_file(conf_file).with_content(%r{trust_store_password: hunter2}) }
78+
it { should contain_file(conf_file).with_content(%r{tags:\s+foo: bar\s+baz: bat}) }
79+
it { should contain_file(conf_file).with_content(%r{domain: my_domain}) }
80+
end
81+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<%
2+
require 'yaml'
3+
4+
if RUBY_VERSION < "1.9"
5+
# Hack to avoid ruby 1.8 always reordering the hashes and
6+
# changing this template resource at every run
7+
# See https://github.com/DataDog/puppet-datadog-agent/issues/43
8+
# Taken from http://www.dzone.com/snippets/generating-yaml-hashes-sorted
9+
class Hash
10+
# Replacing the to_yaml function so it'll serialize hashes sorted (by their keys)
11+
#
12+
# Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb
13+
def to_yaml( opts = {} )
14+
YAML::quick_emit( object_id, opts ) do |out|
15+
out.map( taguri, to_yaml_style ) do |map|
16+
sort.each do |k, v| # <-- here's my addition (the 'sort')
17+
map.add( k, v )
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end
24+
%>
25+
26+
<%= {'init_config'=>@init_config, 'instances'=>@instances}.to_yaml %>

0 commit comments

Comments
 (0)