Skip to content

Commit

Permalink
plugin: update cpu for collectd 5.8
Browse files Browse the repository at this point in the history
This change adds options for cpu plugin present since collectd 5.8
  • Loading branch information
sileht committed May 25, 2018
1 parent cd9486e commit 29bee9e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions manifests/plugin/cpu.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Boolean $reportbycpu = true,
Boolean $valuespercentage = false,
Boolean $reportnumcpu = false,
Boolean $reportgueststate = false,
Boolean $subtractgueststate = true,
Optional[Integer[1]] $interval = undef,
) {

Expand Down
40 changes: 40 additions & 0 deletions spec/classes/collectd_plugin_cpu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
it "Will not include ValuesPercentage in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.not_to contain_file('cpu.load').with_content(%r{ValuesPercentage})
end

it "Will not include ReportGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.not_to contain_file('cpu.load').with_content(%r{ReportGuestState})
end
it "Will not include SubtractGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.not_to contain_file('cpu.load').with_content(%r{SubtractGuestState})
end
end

context 'cpu options should be set with collectd 5.5' do
Expand All @@ -58,6 +65,13 @@
it "Will include ValuesPercentage in #{options[:plugin_conf_dir]}/10-cpu.conf" do
is_expected.to contain_file('cpu.load').with_content(%r{ValuesPercentage true})
end

it "Will not include ReportGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.not_to contain_file('cpu.load').with_content(%r{ReportGuestState})
end
it "Will not include SubtractGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.not_to contain_file('cpu.load').with_content(%r{SubtractGuestState})
end
end

context 'cpu options should be set with collectd 5.6' do
Expand All @@ -73,6 +87,32 @@
it "Will include ValuesPercentage in #{options[:plugin_conf_dir]}/10-cpu.conf" do
is_expected.to contain_file('cpu.load').with_content(%r{ReportNumCpu true})
end

it "Will not include ReportGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.not_to contain_file('cpu.load').with_content(%r{ReportGuestState})
end
it "Will not include SubtractGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.not_to contain_file('cpu.load').with_content(%r{SubtractGuestState})
end
end

context 'cpu options should be set with collectd 5.8' do
let :facts do
facts.merge(collectd_version: '5.8')
end
let :params do
{
reportgueststate: true,
subtractgueststate: false
}
end

it "Will include ReportGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.to contain_file('cpu.load').with_content(%r{ReportGuestState true})
end
it "Will include SubtractGuestState in #{options[:plugin_conf_dir]}d/10-cpu.conf" do
is_expected.to contain_file('cpu.load').with_content(%r{SubtractGuestState false})
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions templates/plugin/cpu.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
<% if scope.lookupvar('collectd::collectd_version_real') and scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.6']) >= 0 -%>
ReportNumCpu <%= @reportnumcpu %>
<% end -%>
<% if scope.lookupvar('collectd::collectd_version_real') and scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.8']) >= 0 -%>
ReportGuestState <%= @reportgueststate %>
SubtractGuestState <%= @subtractgueststate %>
<% end -%>
</Plugin>
<% end -%>

0 comments on commit 29bee9e

Please sign in to comment.