Skip to content

Commit

Permalink
plugin: add battery plugin
Browse files Browse the repository at this point in the history
this change adds the battery plugin
  • Loading branch information
sileht authored and bastelfreak committed May 31, 2018
1 parent 2ad7881 commit 5f741b6
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions manifests/plugin/battery.pp
Original file line number Diff line number Diff line change
@@ -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'),
}
}
70 changes: 70 additions & 0 deletions spec/classes/collectd_plugin_battery_spec.rb
Original file line number Diff line number Diff line change
@@ -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 = <<EOS
# Generated by Puppet
<LoadPlugin battery>
Globals false
</LoadPlugin>
<Plugin "battery">
ValuesPercentage false
ReportDegraded false
QueryStateFS false
</Plugin>
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 = <<EOS
# Generated by Puppet
<LoadPlugin battery>
Globals false
</LoadPlugin>
<Plugin "battery">
ValuesPercentage true
ReportDegraded true
QueryStateFS true
</Plugin>
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
5 changes: 5 additions & 0 deletions templates/plugin/battery.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Plugin "battery">
ValuesPercentage <%= $collectd::plugin::battery::values_percentage %>
ReportDegraded <%= $collectd::plugin::battery::report_degraded %>
QueryStateFS <%= $collectd::plugin::battery::query_state_fs %>
</Plugin>

0 comments on commit 5f741b6

Please sign in to comment.