From 32fb31c8f752f7eee3219a6e8d416b363c88cdd0 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Fri, 25 May 2018 13:56:34 +0200 Subject: [PATCH] plugin: update cpu for collectd 5.8 This change adds options for cpu plugin present since collectd 5.8 --- manifests/plugin/cpu.pp | 4 ++- spec/classes/collectd_plugin_cpu_spec.rb | 40 ++++++++++++++++++++++++ templates/plugin/cpu.conf.epp | 14 +++++++++ templates/plugin/cpu.conf.erb | 10 ------ 4 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 templates/plugin/cpu.conf.epp delete mode 100644 templates/plugin/cpu.conf.erb diff --git a/manifests/plugin/cpu.pp b/manifests/plugin/cpu.pp index db4367e30..d1b598fb4 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, ) { @@ -12,7 +14,7 @@ collectd::plugin { 'cpu': ensure => $ensure, - content => template('collectd/plugin/cpu.conf.erb'), + content => epp('collectd/plugin/cpu.conf.epp'), interval => $interval, } } 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.epp b/templates/plugin/cpu.conf.epp new file mode 100644 index 000000000..a26861ccf --- /dev/null +++ b/templates/plugin/cpu.conf.epp @@ -0,0 +1,14 @@ +<% if versioncmp($::collectd::collectd_version_real, '5.5') >= 0 { -%> + + ReportByState <%= $::collectd::plugin::cpu::reportbystate %> + ReportByCpu <%= $::collectd::plugin::cpu::reportbycpu %> + ValuesPercentage <%= $::collectd::plugin::cpu::valuespercentage %> +<% if versioncmp($::collectd::collectd_version_real, '5.6') >= 0 { -%> + ReportNumCpu <%= $::collectd::plugin::cpu::reportnumcpu %> +<% } -%> +<% if versioncmp($::collectd::collectd_version_real, '5.8') >= 0 { -%> + ReportGuestState <%= $::collectd::plugin::cpu::reportgueststate %> + SubtractGuestState <%= $::collectd::plugin::cpu::subtractgueststate %> +<% } -%> + +<% } -%> diff --git a/templates/plugin/cpu.conf.erb b/templates/plugin/cpu.conf.erb deleted file mode 100644 index 57d4b2b53..000000000 --- a/templates/plugin/cpu.conf.erb +++ /dev/null @@ -1,10 +0,0 @@ -<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.5']) >= 0) -%> - - ReportByState <%= @reportbystate %> - ReportByCpu <%= @reportbycpu %> - ValuesPercentage <%= @valuespercentage %> -<% if scope.lookupvar('collectd::collectd_version_real') and scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.6']) >= 0 -%> - ReportNumCpu <%= @reportnumcpu %> -<% end -%> - -<% end -%>