diff --git a/README.md b/README.md index 52406b1dc..47b2200c2 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ documentation for each plugin for configurable attributes. below) * `amqp` (see [collectd::plugin::amqp](#class-collectdpluginamqp) below) * `apache` (see [collectd::plugin::apache](#class-collectdpluginapache) below) +* `battery` (see [collectd::plugin::battery](#class-collectdpluginbattery) below) * `bind` (see [collectd::plugin::bind](#class-collectdpluginbind) below) * `ceph` (see [collectd::plugin::ceph](#class-ceph) below) * `cgroups` (see [collectd::plugin::cgroups](#class-collectdplugincgroups) below) @@ -261,6 +262,17 @@ class { 'collectd::plugin::apache': } ``` +### Class: `collectd::plugin::battery` + +```puppet +class { 'collectd::plugin::battery': + interval => 30, + values_percentage => true, + report_degraded => true, + query_state_fs => true, +} +``` + ### Class: `collectd::plugin::bind` ```puppet diff --git a/manifests/plugin/battery.pp b/manifests/plugin/battery.pp new file mode 100644 index 000000000..49b332076 --- /dev/null +++ b/manifests/plugin/battery.pp @@ -0,0 +1,51 @@ +#== Class: collectd::plugin::battery +# +# Class to manage battery write plugin for collectd +# +# Documentation: +# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_battery +# +# === Parameters +# +# [*ensure*] +# Ensure param for collectd::plugin type. +# Defaults to 'ensure' +# +# [*interval*] +# Interval setting for the plugin +# Defaults to undef +# +# [*values_percentage*] +# When enabled, remaining capacity is reported as a percentage instead of raw +# data (most likely in "Wh") +# Defaults to false +# +# [*report_degraded*] +# When set to true, the battery plugin will report three values: charged +# (remaining capacity), discharged (difference between "last full capacity" +# and "remaining capacity") and degraded (difference between "design capacity" +# and "last full capacity"). Otherwise only the remaining capacity is +# reported. +# Defaults to false +# +# [*query_state_fs*] +# When set to true, the battery plugin will only read statistics related to +# battery performance as exposed by StateFS at /run/state. +# Defaults to false +# +class collectd::plugin::battery ( + Enum['present', 'absent'] $ensure = 'present', + Optional[Integer] $interval = undef, + Boolean $values_percentage = false, + Boolean $report_degraded = false, + Boolean $query_state_fs = false, +) { + + include collectd + + collectd::plugin { 'battery': + ensure => $ensure, + interval => $interval, + content => epp('collectd/plugin/battery.conf.epp'), + } +} diff --git a/spec/classes/collectd_plugin_battery_spec.rb b/spec/classes/collectd_plugin_battery_spec.rb new file mode 100644 index 000000000..dc08a229f --- /dev/null +++ b/spec/classes/collectd_plugin_battery_spec.rb @@ -0,0 +1,70 @@ +require 'spec_helper' + +describe 'collectd::plugin::battery', type: :class do + on_supported_os(baseline_os_hash).each do |os, facts| + context "on #{os} " do + let :facts do + facts + end + + options = os_specific_options(facts) + context 'default' do + it 'defaults' do + content = < + Globals false + + + + ValuesPercentage false + ReportDegraded false + QueryStateFS false + + +EOS + + is_expected.to compile.with_all_deps + is_expected.to contain_file('battery.load').with( + content: content, + path: "#{options[:plugin_conf_dir]}/10-battery.conf" + ) + end + end + + options = os_specific_options(facts) + context 'multiple instances' do + let :params do + { + 'values_percentage' => true, + 'report_degraded' => true, + 'query_state_fs' => true + } + end + + it 'overrides defaults' do + content = < + Globals false + + + + ValuesPercentage true + ReportDegraded true + QueryStateFS true + + +EOS + + is_expected.to compile.with_all_deps + is_expected.to contain_class('collectd') + is_expected.to contain_file('battery.load').with( + content: content, + path: "#{options[:plugin_conf_dir]}/10-battery.conf" + ) + end + end + end + end +end diff --git a/templates/plugin/battery.conf.epp b/templates/plugin/battery.conf.epp new file mode 100644 index 000000000..004c20978 --- /dev/null +++ b/templates/plugin/battery.conf.epp @@ -0,0 +1,5 @@ + + ValuesPercentage <%= $collectd::plugin::battery::values_percentage %> + ReportDegraded <%= $collectd::plugin::battery::report_degraded %> + QueryStateFS <%= $collectd::plugin::battery::query_state_fs %> +