Skip to content

Commit

Permalink
Merge pull request redhat-openstack#297 from ChrisHeerschap/master
Browse files Browse the repository at this point in the history
adding ValuesAbsolute and ValuesPercentage to memory and swap
  • Loading branch information
blkperl committed Jul 27, 2015
2 parents a35e172 + ebbe129 commit 125b28c
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 7 deletions.
13 changes: 11 additions & 2 deletions manifests/plugin/memory.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# https://collectd.org/wiki/index.php/Plugin:Memory
class collectd::plugin::memory (
$ensure = present,
$interval = undef,
$ensure = present,
$valuesabsolute = true,
$valuespercentage = false,
$interval = undef,
) {

validate_bool(
$valuesabsolute,
$valuespercentage,
)

collectd::plugin {'memory':
ensure => $ensure,
content => template('collectd/plugin/memory.conf.erb'),
interval => $interval,
}
}
14 changes: 9 additions & 5 deletions manifests/plugin/swap.pp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# https://collectd.org/wiki/index.php/Plugin:Swap
class collectd::plugin::swap (
$ensure = present,
$interval = undef,
$reportbydevice = false,
$reportbytes = true,
$ensure = present,
$interval = undef,
$reportbydevice = false,
$reportbytes = true,
$valuesabsolute = true,
$valuespercentage = false,
) {
validate_bool(
$reportbydevice,
$reportbytes
$reportbytes,
$valuesabsolute,
$valuespercentage
)

collectd::plugin {'swap':
Expand Down
70 changes: 70 additions & 0 deletions spec/classes/collectd_plugin_memory_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'spec_helper'

describe 'collectd::plugin::memory', :type => :class do

context ':ensure => present, default params' do
let :facts do
{:osfamily => 'RedHat'}
end
it 'Will create /etc/collectd.d/10-memory.conf' do
should contain_file('memory.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-memory.conf',
:content => /LoadPlugin memory/,
})
end
end

context ':ensure => present, specific params, collectd version 5.4.2' do
let :facts do
{ :osfamily => 'Redhat',
:collectd_version => '5.4.2'
}
end

it 'Will create /etc/collectd.d/10-memory.conf for collectd < 5.5' do
should contain_file('memory.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-memory.conf',
:content => /LoadPlugin memory/,
})
end

it 'Will not include ValuesPercentage in /etc/collectd.d/10-memory.conf' do
should_not contain_file('memory.load').with_content(/ValuesPercentage/)
end
end

context ':ensure => present, specific params, collectd version 5.5.0' do
let :facts do
{ :osfamily => 'Redhat',
:collectd_version => '5.5.0'
}
end

it 'Will create /etc/collectd.d/10-memory.conf for collectd >= 5.5' do
should contain_file('memory.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-memory.conf',
:content => "# Generated by Puppet\n<LoadPlugin memory>\n Globals false\n</LoadPlugin>\n\n<Plugin memory>\n ValuesAbsolute = true\n ValuesPercentage = false\n</Plugin>\n\n",
})
end
end

context ':ensure => absent' do
let :facts do
{:osfamily => 'RedHat'}
end
let :params do
{:ensure => 'absent'}
end

it 'Will not create /etc/collectd.d/10-memory.conf' do
should contain_file('memory.load').with({
:ensure => 'absent',
:path => '/etc/collectd.d/10-memory.conf',
})
end
end
end

16 changes: 16 additions & 0 deletions spec/classes/collectd_plugin_swap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@
end
end

context ':ensure => present, specific params, collectd version 5.5.0' do
let :facts do
{ :osfamily => 'Redhat',
:collectd_version => '5.5.0'
}
end

it 'Will create /etc/collectd.d/10-swap.conf for collectd >= 5.5' do
should contain_file('swap.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-swap.conf',
:content => "# Generated by Puppet\n<LoadPlugin swap>\n Globals false\n</LoadPlugin>\n\n<Plugin swap>\n ReportByDevice false\n ReportBytes true\n ValuesAbsolute = true\n ValuesPercentage = false\n</Plugin>\n\n",
})
end
end

context ':ensure => absent' do
let :facts do
{:osfamily => 'RedHat'}
Expand Down
6 changes: 6 additions & 0 deletions templates/plugin/memory.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.5']) >= 0) -%>
<Plugin memory>
ValuesAbsolute = <%= @valuesabsolute %>
ValuesPercentage = <%= @valuespercentage %>
</Plugin>
<% end -%>
4 changes: 4 additions & 0 deletions templates/plugin/swap.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<% if @collectd_version and scope.function_versioncmp([@collectd_version, '5.2']) > 0 -%>
ReportBytes <%= @reportbytes %>
<% end -%>
<% if @collectd_version and scope.function_versioncmp([@collectd_version, '5.5']) > 0 -%>
ValuesAbsolute = <%= @valuesabsolute %>
ValuesPercentage = <%= @valuespercentage %>
<% end -%>
</Plugin>

0 comments on commit 125b28c

Please sign in to comment.