Skip to content

Commit

Permalink
Merge pull request redhat-openstack#226 from 3dna/jmx-plugin
Browse files Browse the repository at this point in the history
java and genericjmx plugins
  • Loading branch information
blkperl committed Jan 24, 2015
2 parents d36948e + fcd63aa commit c3d912b
Show file tree
Hide file tree
Showing 14 changed files with 600 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ documentation for each plugin for configurable attributes.
* `entropy` (see [collectd::plugin::entropy](#class-collectdpluginentropy) below)
* `exec` (see [collectd::plugin::exec](#class-collectdpluginexec) below)
* `filecount` (see [collectd::plugin::filecount](#class-collectdpluginfilecount) below)
* `genericjmx` (see [collectd::plugin::genericjmx](#class-collectdplugingenericjmx) below)
* `interface` (see [collectd::plugin::interface](#class-collectdplugininterface) below)
* `iptables` (see [collectd::plugin::iptables](#class-collectdpluginiptables) below)
* `irq` (see [collectd::plugin::irq](#class-collectdpluginirq) below)
* `java` (see [collectd::plugin::java](#class-collectdpluginjava) below)
* `load` (see [collectd::plugin::load](#class-collectdpluginload) below)
* `logfile` (see [collectd::plugin::logfile](#class-collectdpluginlogfile) below)
* `libvirt` (see [collectd::plugin::libvirt](#class-collectdpluginlibvirt) below)
Expand Down Expand Up @@ -303,6 +305,41 @@ class { 'collectd::plugin::filecount':
},
}
```

####Class: `collectd::plugin::genericjmx`

```puppet
include collectd::plugin::genericjmx
collectd::plugin::genericjmx::mbean {
'garbage_collector':
object_name => 'java.lang:type=GarbageCollector,*',
instance_prefix => 'gc-',
instance_from => 'name',
values => [
{
type => 'invocations',
table => false,
attribute => 'CollectionCount',
},
{
type => 'total_time_in_ms',
instance_prefix => 'collection_time',
table => false,
attribute => 'CollectionTime',
},
];
}
collectd::plugin::genericjmx::connection {
'java_app':
host => $fqdn,
service_url => 'service:jmx:rmi:///jndi/rmi://localhost:3637/jmxrmi',
collect => [ 'memory-heap', 'memory-nonheap','garbage_collector' ],
}
```

####Class: `collectd::plugin::interface`

```puppet
Expand Down Expand Up @@ -332,6 +369,12 @@ class { 'collectd::plugin::iptables':
}
```

####Class: `collectd::plugin::java`

```puppet
class { 'collectd::plugin::java': }
```

####Class: `collectd::plugin::load`

```puppet
Expand Down
7 changes: 7 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$service_name = 'collectd'
$config_file = "${collectd_dir}/collectd.conf"
$root_group = 'root'
$java_dir = '/usr/share/collectd/java'
}
'Solaris': {
$package = 'CSWcollectd'
Expand All @@ -19,6 +20,7 @@
$service_name = 'collectd'
$config_file = "${collectd_dir}/collectd.conf"
$root_group = 'root'
$java_dir = undef
}
'Redhat': {
$package = 'collectd'
Expand All @@ -28,6 +30,7 @@
$service_name = 'collectd'
$config_file = '/etc/collectd.conf'
$root_group = 'root'
$java_dir = '/usr/share/collectd/java'
}
'Suse': {
$package = 'collectd'
Expand All @@ -37,6 +40,7 @@
$service_name = 'collectd'
$config_file = '/etc/collectd.conf'
$root_group = 'root'
$java_dir = undef
}
'FreeBSD': {
$package = 'collectd5'
Expand All @@ -46,6 +50,7 @@
$service_name = 'collectd'
$config_file = '/usr/local/etc/collectd.conf'
$root_group = 'wheel'
$java_dir = undef
}
'Archlinux': {
$package = 'collectd'
Expand All @@ -55,6 +60,7 @@
$service_name = 'collectd'
$config_file = '/etc/collectd.conf'
$root_group = 'wheel'
$java_dir = undef
}
'Gentoo': {
$package = 'app-admin/collectd'
Expand All @@ -64,6 +70,7 @@
$service_name = 'collectd'
$config_file = '/etc/collectd.conf'
$root_group = 'collectd'
$java_dir = undef
}

default: {
Expand Down
29 changes: 29 additions & 0 deletions manifests/plugin/genericjmx.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://collectd.org/wiki/index.php/Plugin:GenericJMX
class collectd::plugin::genericjmx (
$jvmarg = [],
) {
include collectd
include collectd::params
include collectd::plugin::java
$class_path = "${collectd::params::java_dir}/collectd-api.jar:${collectd::params::java_dir}/generic-jmx.jar"
$config_file = "${collectd::params::plugin_conf_dir}/15-genericjmx.conf"

concat { $config_file:
mode => '0640',
owner => 'root',
group => $collectd::params::root_group,
notify => Service['collectd'],
ensure_newline => true,
}
concat::fragment {
'collectd_plugin_genericjmx_conf_header':
order => '00',
content => template('collectd/plugin/genericjmx.conf.header.erb'),
target => $config_file;
'collectd_plugin_genericjmx_conf_footer':
order => '99',
content => " </Plugin>\n</Plugin>\n",
target => $config_file;
}

}
16 changes: 16 additions & 0 deletions manifests/plugin/genericjmx/connection.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# https://collectd.org/wiki/index.php/Plugin:GenericJMX
define collectd::plugin::genericjmx::connection (
$host = $name,
$service_url,
$user = undef,
$password = undef,
$instance_prefix = undef,
$collect,
) {
include collectd::plugin::genericjmx
concat::fragment { "collectd_plugin_genericjmx_conf_${name}":
order => 20,
content => template('collectd/plugin/genericjmx/connection.conf.erb'),
target => $collectd::plugin::genericjmx::config_file;
}
}
17 changes: 17 additions & 0 deletions manifests/plugin/genericjmx/mbean.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://collectd.org/wiki/index.php/Plugin:GenericJMX
define collectd::plugin::genericjmx::mbean (
$object_name,
$instance_prefix = undef,
$instance_from = undef,
$values,
) {
include collectd::plugin::genericjmx
validate_array($values)

concat::fragment {
"collectd_plugin_genericjmx_conf_${name}":
order => '10',
content => template('collectd/plugin/genericjmx/mbean.conf.erb'),
target => $collectd::plugin::genericjmx::config_file;
}
}
12 changes: 12 additions & 0 deletions manifests/plugin/java.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://collectd.org/wiki/index.php/Plugin:Java
class collectd::plugin::java (
$ensure = present,
$jvmarg = [],
$interval = undef,
) {
collectd::plugin { 'java':
ensure => $ensure,
content => template('collectd/plugin/java.conf.erb'),
interval => $interval,
}
}
72 changes: 72 additions & 0 deletions spec/classes/collectd_plugin_genericjmx_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'spec_helper'

describe 'collectd::plugin::genericjmx', :type => :class do
let (:facts) {{
:osfamily => 'Debian',
:id => 'root',
:concat_basedir => tmpfilename('collectd-genericjmx'),
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}}

let (:config_filename) { '/etc/collectd/conf.d/15-genericjmx.conf' }

context 'defaults' do
it 'will include the java plugin' do
should contain_class('collectd::plugin::java')
end

it 'will load the genericjmx plugin' do
should contain_concat(config_filename).with({
:ensure => 'present',
:mode => '0640',
:owner => 'root',
:group => 'root',
:ensure_newline => true
})
end

it { should contain_concat(config_filename).that_notifies('Service[collectd]') }

it do
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').with({
:order => '00',
:target => config_filename,
:content => /<Plugin "java">.+LoadPlugin "org\.collectd\.java\.GenericJMX".+<Plugin "GenericJMX">/m
})
end

it do
should contain_concat__fragment('collectd_plugin_genericjmx_conf_footer').with({
:order => '99',
:target => config_filename,
:content => %r{</Plugin>.+</Plugin>}m,
})
end

end

context 'jvmarg parameter array' do
let (:params) {{ :jvmarg => %w{ foo bar baz } }}
it 'should have multiple jvmarg parameters' do
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').with_content(/JVMArg "foo".*JVMArg "bar".*JVMArg "baz"/m)
end
end

context 'jvmarg parameter string' do
let (:params) {{ :jvmarg => "bat" }}
it 'should have one jvmarg parameter' do
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').with_content(/JVMArg "bat"/)
end
it 'should have ONLY one jvmarg parameter other than classpath' do
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').without_content(/(.*JVMArg.*){3,}/m)
end
end

context 'jvmarg parameter empty' do
let (:params) {{ :jvmarg => [] }}
it 'should not have any jvmarg parameters other than classpath' do
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').without_content(/(.*JVMArg.*){2,}/m)
end
end
end

64 changes: 64 additions & 0 deletions spec/classes/collectd_plugin_java_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'spec_helper'

describe 'collectd::plugin::java', :type => :class do
let :facts do
{:osfamily => 'RedHat'}
end

context ':ensure => present, defaults' do
it 'Will load the plugin' do
should contain_collectd__plugin('java').with({
:ensure => 'present',
})
end
end

context ':ensure => absent' do
let (:params) {{
:ensure => 'absent',
}}

it 'will not load the plugin' do
should contain_collectd__plugin('java').with({
:ensure => 'absent'
})
end
end

context 'jvmarg parameter array' do
let (:params) {{
:jvmarg => %w{ foo bar baz }
}}

it 'will have multiple jvmarg parameters' do
should contain_collectd__plugin('java').with_content(/JVMArg "foo".+JVMArg "bar".+JVMArg "baz"/m)
end
end

context 'jvmarg parameter string' do
let (:params) {{
:jvmarg => 'bat'
}}

it 'will have a JVMArg parameter' do
should contain_collectd__plugin('java').with_content(/JVMArg "bat"/)
end

it 'will only have one JVMArg parameter' do
should contain_collectd__plugin('java').without_content(/(.*JVMArg.*){2,}/m)
end
end

context 'jvmarg parameter empty' do
let (:params) {{
:jvmarg => [],
}}

it 'will not have a <Plugin java> stanza' do
should contain_collectd__plugin('java').without_content(/<Plugin java>/)
end
it 'will not have any jvmarg parameters' do
should contain_collectd__plugin('java').without_content(/JVMArg/)
end
end
end
Loading

0 comments on commit c3d912b

Please sign in to comment.