-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New collectd::plugin::table::table type
For example to parse `/proc/uptime` with the collectd table plugin can now be defined with: ``` collectd::plugin::table::table{'/proc/uptime': table => { 'plugin' => 'uptime', 'instance' => 'first', 'separator' => ' ', 'results' => [{ 'type' => 'gauge', 'values_from' => [0], }], } } ``` Previously it was only possible to specify tables at one location with the class `collectd::plugin::table`. The class `collectd::plugin::table` remains unchanged.
- Loading branch information
1 parent
525cdde
commit b3ed548
Showing
6 changed files
with
340 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
# https://collectd.org/wiki/index.php/Chains | ||
# @summary Load and configure the table plugin | ||
# @see https://collectd.org/wiki/index.php/Plugin:Table | ||
# | ||
# @param tables `<Table>` blocks for table plugin | ||
# @param ensure Should the plugin be configured | ||
# @param order Prefix of file in collectd config directory | ||
# | ||
# @example Parse `/proc/pressure/cpu` | ||
# class {'collectd::plugin::table': | ||
# tables => { | ||
# '/proc/pressure/cpu' => { | ||
# 'plugin' => 'psi', | ||
# 'instance => 'cpu', | ||
# 'seperator' => ' =', | ||
# 'results' => [{ | ||
# 'type' => 'gauge', | ||
# 'instance_from' => [0], | ||
# 'instance_prefix' => 'arg10', | ||
# 'values_from' => [2], | ||
# }], | ||
# } | ||
# } | ||
# } | ||
# | ||
class collectd::plugin::table ( | ||
Hash[String, Collectd::Table::Table, 1] $tables, | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Integer $order = 10, | ||
Optional[Hash[String, Collectd::Table::Table, 1]] $tables = undef, | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Integer $order = 10, | ||
) { | ||
include collectd | ||
|
||
$_content = $tables ? { | ||
Undef => undef, | ||
default => epp('collectd/plugin/table.conf.epp', { 'tables' => $tables }), | ||
} | ||
|
||
collectd::plugin { 'table': | ||
ensure => $ensure, | ||
content => epp('collectd/plugin/table.conf.epp'), | ||
content => $_content, | ||
order => $order, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# @summary table definition for table plugin | ||
# @param $tablename Name of table typically a filename | ||
# @param $table Table definition | ||
# | ||
# @example Parse the /proc/uptime file | ||
# collectd::plugin::table::table{'/proc/uptime': | ||
# table => { | ||
# 'plugin' => 'uptime', | ||
# 'instance' => 'first', | ||
# 'separator' => ' ', | ||
# 'results' => [{ | ||
# 'type' => 'gauge', | ||
# 'values_from' => [0], | ||
# }], | ||
# } | ||
# } | ||
# | ||
define collectd::plugin::table::table ( | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Stdlib::Unixpath $tablename = $name, | ||
Collectd::Table::Table $table, | ||
) { | ||
include collectd::plugin::table | ||
|
||
$_safer_file_name = regsubst($name,'/','_','G') | ||
|
||
# Must come lexically after 10-table.conf | ||
file { "table-${tablename}.conf": | ||
ensure => file, | ||
owner => $collectd::config_owner, | ||
path => "${collectd::plugin_conf_dir}/${collectd::plugin::table::order}-tabletable-${_safer_file_name}.conf", | ||
group => $collectd::config_group, | ||
mode => $collectd::config_mode, | ||
content => epp('collectd/plugin/table.conf.epp', { 'tables' => { $tablename => $table } }), | ||
notify => Service[$collectd::service_name], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper_acceptance' | ||
|
||
describe 'collectd::plugin::table::table' do | ||
context 'basic parameters' do | ||
# Using puppet_apply as a helper | ||
it 'works idempotently with no errors' do | ||
pp = <<-EOS | ||
class{'collectd': | ||
utils => true, | ||
purge => true, | ||
recurse => true, | ||
purge_config => true, | ||
} | ||
# ubuntu 18.04 has old collectd version. | ||
$_plugin = $facts['os']['release']['major'] ? { | ||
'18.04' => undef, | ||
default => 'uptime', | ||
} | ||
collectd::plugin::table::table{'/proc/uptime': | ||
table => { | ||
'plugin' => $_plugin, | ||
'instance' => 'first', | ||
'separator' => ' ', | ||
'results' => [{ | ||
'type' => 'gauge', | ||
'values_from' => [0], | ||
}], | ||
}, | ||
} | ||
# Configure one write plugin to keep logs quiet | ||
class{'collectd::plugin::csv':} | ||
# Create a socket to query | ||
class{'collectd::plugin::unixsock': | ||
socketfile => '/var/run/collectd-sock', | ||
socketgroup => 'root', | ||
deletesocket => true, | ||
} | ||
EOS | ||
# Run 3 times since the collectd_version | ||
# fact is impossible until collectd is | ||
# installed. | ||
apply_manifest(pp, catch_failures: false) | ||
apply_manifest(pp, catch_failures: true) | ||
apply_manifest(pp, catch_changes: true) | ||
# Wait to get some data | ||
shell('sleep 10') | ||
end | ||
|
||
describe service('collectd') do | ||
it { is_expected.to be_running } | ||
end | ||
|
||
describe command('collectdctl -s /var/run/collectd-sock listval') do | ||
its(:exit_status) { is_expected.to eq 0 } | ||
|
||
case fact('os.release.major') | ||
when '18.04' | ||
its(:stdout) { is_expected.to match %r{table-first/gauge} } | ||
else | ||
its(:stdout) { is_expected.to match %r{uptime-first/gauge} } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.