diff --git a/manifests/plugin/cpu.pp b/manifests/plugin/cpu.pp index db4367e30..c4887ca8a 100644 --- a/manifests/plugin/cpu.pp +++ b/manifests/plugin/cpu.pp @@ -5,6 +5,8 @@ Boolean $reportbycpu = true, Boolean $valuespercentage = false, Boolean $reportnumcpu = false, + Boolean $reportgueststate = false, + Boolean $subtractgueststate = true, Optional[Integer[1]] $interval = undef, ) { diff --git a/spec/classes/collectd_plugin_cpu_spec.rb b/spec/classes/collectd_plugin_cpu_spec.rb index c02a49fec..1362d3540 100644 --- a/spec/classes/collectd_plugin_cpu_spec.rb +++ b/spec/classes/collectd_plugin_cpu_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/templates/plugin/cpu.conf.erb b/templates/plugin/cpu.conf.erb index 57d4b2b53..314c9d924 100644 --- a/templates/plugin/cpu.conf.erb +++ b/templates/plugin/cpu.conf.erb @@ -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 -%> <% end -%>