Skip to content

Commit 5d74d60

Browse files
authored
Merge pull request #1021 from traylenator/multitable
New collectd::plugin::table::table type
2 parents 525cdde + b3ed548 commit 5d74d60

File tree

6 files changed

+340
-11
lines changed

6 files changed

+340
-11
lines changed

REFERENCE.md

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
* [`collectd::plugin::swap`](#collectd--plugin--swap): https://collectd.org/wiki/index.php/Plugin:Swap
9696
* [`collectd::plugin::sysevent`](#collectd--plugin--sysevent): == Class: collectd::plugin::sysevent Class to manage sysevent plugin for collectd Documentation: https://collectd.org/documentation/manpa
9797
* [`collectd::plugin::syslog`](#collectd--plugin--syslog): https://collectd.org/wiki/index.php/Plugin:SysLog
98-
* [`collectd::plugin::table`](#collectd--plugin--table): https://collectd.org/wiki/index.php/Chains
98+
* [`collectd::plugin::table`](#collectd--plugin--table): Load and configure the table plugin
9999
* [`collectd::plugin::tail`](#collectd--plugin--tail): Tail plugin https://collectd.org/wiki/index.php/Plugin:Tail
100100
* [`collectd::plugin::tail_csv`](#collectd--plugin--tail_csv): https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_tail_csv
101101
* [`collectd::plugin::target_v5upgrade`](#collectd--plugin--target_v5upgrade): https://collectd.org/wiki/index.php/Target:v5_upgrade
@@ -164,6 +164,7 @@
164164
* [`collectd::plugin::python::module`](#collectd--plugin--python--module): Single module definition
165165
* [`collectd::plugin::snmp::data`](#collectd--plugin--snmp--data): https://collectd.org/wiki/index.php/Plugin:SNMP
166166
* [`collectd::plugin::snmp::host`](#collectd--plugin--snmp--host): https://collectd.org/wiki/index.php/Plugin:SNMP
167+
* [`collectd::plugin::table::table`](#collectd--plugin--table--table): table definition for table plugin
167168
* [`collectd::plugin::tail::file`](#collectd--plugin--tail--file)
168169
* [`collectd::plugin::write_graphite::carbon`](#collectd--plugin--write_graphite--carbon): a single graphite backend
169170
* [`collectd::type`](#collectd--type)
@@ -6179,7 +6180,32 @@ Default value: `undef`
61796180

61806181
### <a name="collectd--plugin--table"></a>`collectd::plugin::table`
61816182

6182-
https://collectd.org/wiki/index.php/Chains
6183+
Load and configure the table plugin
6184+
6185+
* **See also**
6186+
* https://collectd.org/wiki/index.php/Plugin:Table
6187+
6188+
#### Examples
6189+
6190+
##### Parse `/proc/pressure/cpu`
6191+
6192+
```puppet
6193+
class {'collectd::plugin::table':
6194+
tables => {
6195+
'/proc/pressure/cpu' => {
6196+
'plugin' => 'psi',
6197+
'instance => 'cpu',
6198+
'seperator' => ' =',
6199+
'results' => [{
6200+
'type' => 'gauge',
6201+
'instance_from' => [0],
6202+
'instance_prefix' => 'arg10',
6203+
'values_from' => [2],
6204+
}],
6205+
}
6206+
}
6207+
}
6208+
```
61836209

61846210
#### Parameters
61856211

@@ -6191,23 +6217,25 @@ The following parameters are available in the `collectd::plugin::table` class:
61916217

61926218
##### <a name="-collectd--plugin--table--tables"></a>`tables`
61936219

6194-
Data type: `Hash[String, Collectd::Table::Table, 1]`
6220+
Data type: `Optional[Hash[String, Collectd::Table::Table, 1]]`
61956221

6222+
`<Table>` blocks for table plugin
61966223

6224+
Default value: `undef`
61976225

61986226
##### <a name="-collectd--plugin--table--ensure"></a>`ensure`
61996227

62006228
Data type: `Enum['present', 'absent']`
62016229

6202-
6230+
Should the plugin be configured
62036231

62046232
Default value: `'present'`
62056233

62066234
##### <a name="-collectd--plugin--table--order"></a>`order`
62076235

62086236
Data type: `Integer`
62096237

6210-
6238+
Prefix of file in collectd config directory
62116239

62126240
Default value: `10`
62136241

@@ -9736,6 +9764,68 @@ Data type: `Optional[String[1]]`
97369764

97379765
Default value: `undef`
97389766

9767+
### <a name="collectd--plugin--table--table"></a>`collectd::plugin::table::table`
9768+
9769+
table definition for table plugin
9770+
9771+
#### Examples
9772+
9773+
##### Parse the /proc/uptime file
9774+
9775+
```puppet
9776+
collectd::plugin::table::table{'/proc/uptime':
9777+
table => {
9778+
'plugin' => 'uptime',
9779+
'instance' => 'first',
9780+
'separator' => ' ',
9781+
'results' => [{
9782+
'type' => 'gauge',
9783+
'values_from' => [0],
9784+
}],
9785+
}
9786+
}
9787+
```
9788+
9789+
#### Parameters
9790+
9791+
The following parameters are available in the `collectd::plugin::table::table` defined type:
9792+
9793+
* [`$tablename`](#-collectd--plugin--table--table---tablename)
9794+
* [`$table`](#-collectd--plugin--table--table---table)
9795+
* [`ensure`](#-collectd--plugin--table--table--ensure)
9796+
* [`tablename`](#-collectd--plugin--table--table--tablename)
9797+
* [`table`](#-collectd--plugin--table--table--table)
9798+
9799+
##### <a name="-collectd--plugin--table--table---tablename"></a>`$tablename`
9800+
9801+
Name of table typically a filename
9802+
9803+
##### <a name="-collectd--plugin--table--table---table"></a>`$table`
9804+
9805+
Table definition
9806+
9807+
##### <a name="-collectd--plugin--table--table--ensure"></a>`ensure`
9808+
9809+
Data type: `Enum['present', 'absent']`
9810+
9811+
9812+
9813+
Default value: `'present'`
9814+
9815+
##### <a name="-collectd--plugin--table--table--tablename"></a>`tablename`
9816+
9817+
Data type: `Stdlib::Unixpath`
9818+
9819+
9820+
9821+
Default value: `$name`
9822+
9823+
##### <a name="-collectd--plugin--table--table--table"></a>`table`
9824+
9825+
Data type: `Collectd::Table::Table`
9826+
9827+
9828+
97399829
### <a name="collectd--plugin--tail--file"></a>`collectd::plugin::tail::file`
97409830

97419831
The collectd::plugin::tail::file class.

manifests/plugin/table.pp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
1-
# https://collectd.org/wiki/index.php/Chains
1+
# @summary Load and configure the table plugin
2+
# @see https://collectd.org/wiki/index.php/Plugin:Table
3+
#
4+
# @param tables `<Table>` blocks for table plugin
5+
# @param ensure Should the plugin be configured
6+
# @param order Prefix of file in collectd config directory
7+
#
8+
# @example Parse `/proc/pressure/cpu`
9+
# class {'collectd::plugin::table':
10+
# tables => {
11+
# '/proc/pressure/cpu' => {
12+
# 'plugin' => 'psi',
13+
# 'instance => 'cpu',
14+
# 'seperator' => ' =',
15+
# 'results' => [{
16+
# 'type' => 'gauge',
17+
# 'instance_from' => [0],
18+
# 'instance_prefix' => 'arg10',
19+
# 'values_from' => [2],
20+
# }],
21+
# }
22+
# }
23+
# }
24+
#
225
class collectd::plugin::table (
3-
Hash[String, Collectd::Table::Table, 1] $tables,
4-
Enum['present', 'absent'] $ensure = 'present',
5-
Integer $order = 10,
26+
Optional[Hash[String, Collectd::Table::Table, 1]] $tables = undef,
27+
Enum['present', 'absent'] $ensure = 'present',
28+
Integer $order = 10,
629
) {
730
include collectd
831

32+
$_content = $tables ? {
33+
Undef => undef,
34+
default => epp('collectd/plugin/table.conf.epp', { 'tables' => $tables }),
35+
}
36+
937
collectd::plugin { 'table':
1038
ensure => $ensure,
11-
content => epp('collectd/plugin/table.conf.epp'),
39+
content => $_content,
1240
order => $order,
1341
}
1442
}

manifests/plugin/table/table.pp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# @summary table definition for table plugin
2+
# @param $tablename Name of table typically a filename
3+
# @param $table Table definition
4+
#
5+
# @example Parse the /proc/uptime file
6+
# collectd::plugin::table::table{'/proc/uptime':
7+
# table => {
8+
# 'plugin' => 'uptime',
9+
# 'instance' => 'first',
10+
# 'separator' => ' ',
11+
# 'results' => [{
12+
# 'type' => 'gauge',
13+
# 'values_from' => [0],
14+
# }],
15+
# }
16+
# }
17+
#
18+
define collectd::plugin::table::table (
19+
Enum['present', 'absent'] $ensure = 'present',
20+
Stdlib::Unixpath $tablename = $name,
21+
Collectd::Table::Table $table,
22+
) {
23+
include collectd::plugin::table
24+
25+
$_safer_file_name = regsubst($name,'/','_','G')
26+
27+
# Must come lexically after 10-table.conf
28+
file { "table-${tablename}.conf":
29+
ensure => file,
30+
owner => $collectd::config_owner,
31+
path => "${collectd::plugin_conf_dir}/${collectd::plugin::table::order}-tabletable-${_safer_file_name}.conf",
32+
group => $collectd::config_group,
33+
mode => $collectd::config_mode,
34+
content => epp('collectd/plugin/table.conf.epp', { 'tables' => { $tablename => $table } }),
35+
notify => Service[$collectd::service_name],
36+
}
37+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'collectd::plugin::table::table' do
6+
context 'basic parameters' do
7+
# Using puppet_apply as a helper
8+
it 'works idempotently with no errors' do
9+
pp = <<-EOS
10+
class{'collectd':
11+
utils => true,
12+
purge => true,
13+
recurse => true,
14+
purge_config => true,
15+
}
16+
17+
# ubuntu 18.04 has old collectd version.
18+
$_plugin = $facts['os']['release']['major'] ? {
19+
'18.04' => undef,
20+
default => 'uptime',
21+
}
22+
collectd::plugin::table::table{'/proc/uptime':
23+
table => {
24+
'plugin' => $_plugin,
25+
'instance' => 'first',
26+
'separator' => ' ',
27+
'results' => [{
28+
'type' => 'gauge',
29+
'values_from' => [0],
30+
}],
31+
},
32+
}
33+
34+
# Configure one write plugin to keep logs quiet
35+
class{'collectd::plugin::csv':}
36+
# Create a socket to query
37+
class{'collectd::plugin::unixsock':
38+
socketfile => '/var/run/collectd-sock',
39+
socketgroup => 'root',
40+
deletesocket => true,
41+
}
42+
43+
EOS
44+
# Run 3 times since the collectd_version
45+
# fact is impossible until collectd is
46+
# installed.
47+
apply_manifest(pp, catch_failures: false)
48+
apply_manifest(pp, catch_failures: true)
49+
apply_manifest(pp, catch_changes: true)
50+
# Wait to get some data
51+
shell('sleep 10')
52+
end
53+
54+
describe service('collectd') do
55+
it { is_expected.to be_running }
56+
end
57+
58+
describe command('collectdctl -s /var/run/collectd-sock listval') do
59+
its(:exit_status) { is_expected.to eq 0 }
60+
61+
case fact('os.release.major')
62+
when '18.04'
63+
its(:stdout) { is_expected.to match %r{table-first/gauge} }
64+
else
65+
its(:stdout) { is_expected.to match %r{uptime-first/gauge} }
66+
end
67+
end
68+
end
69+
end

0 commit comments

Comments
 (0)