From f3eaad2754a1ee92582e449687b3069ac0b44c8c Mon Sep 17 00:00:00 2001 From: Piotr Kurpik Date: Sun, 12 Jul 2015 14:33:42 +0200 Subject: [PATCH] add support for aggregation plugin and chains --- README.md | 60 +++++++++++++++++++ manifests/plugin/aggregation.pp | 16 +++++ manifests/plugin/aggregation/aggregator.pp | 34 +++++++++++ manifests/plugin/chain.pp | 20 +++++++ .../plugin/aggregation-aggregator.conf.erb | 55 +++++++++++++++++ templates/plugin/chain.conf.erb | 23 +++++++ 6 files changed, 208 insertions(+) create mode 100644 manifests/plugin/aggregation.pp create mode 100644 manifests/plugin/aggregation/aggregator.pp create mode 100644 manifests/plugin/chain.pp create mode 100644 templates/plugin/aggregation-aggregator.conf.erb create mode 100644 templates/plugin/chain.conf.erb diff --git a/README.md b/README.md index 06ba0236a..51f292891 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,11 @@ Configurable Plugins Parameters will vary widely between plugins. See the collectd documentation for each plugin for configurable attributes. +* `aggregation` (see [collectd::plugin::aggregation](#class-collectdpluginaggregation) below) * `amqp` (see [collectd::plugin::amqp](#class-collectdpluginamqp) below) * `apache` (see [collectd::plugin::apache](#class-collectdpluginapache) below) * `bind` (see [collectd::plugin::bind](#class-collectdpluginbind) below) +* `chain` (see [collectd::plugin::chain](#class-chain) below) * `conntrack` (see [collectd::plugin::conntrack](#class-conntrack) below) * `cpu` (see [collectd::plugin::cpu](#class-collectdplugincpu) below) * `cpufreq` (see [collectd::plugin::cpufreq](#class-collectdplugincpufreq) below) @@ -114,6 +116,33 @@ documentation for each plugin for configurable attributes. * `write_riemann` (see [collectd::plugin::write_riemann](#class-collectdpluginwrite_riemann) below) * `zfs_arc` (see [collectd::plugin::zfs_arc](#class-collectdpluginzfs_arc) below) +####Class: `collectd::plugin::aggregation` + +```puppet +collectd::plugin::aggregation::aggregator { + cpu': + plugin => 'cpu', + type => 'cpu', + groupby => ["Host", "TypeInstance",], + calculateaverage => true, +} +``` + +You can as well configure this plugin with a parameterized class : + +```puppet +class { 'collectd::plugin::aggregation': + aggregators => { + cpu' => { + plugin => 'cpu', + type => 'cpu', + groupby => ["Host", "TypeInstance",], + calculateaverage => true, + }, + }, +} +``` + ####Class: `collectd::plugin::amqp` ```puppet @@ -148,6 +177,37 @@ class { 'collectd::plugin::bind': } ``` +####Class: `collectd::plugin::chain` + +```puppet +class { 'collectd::plugin::chain': + chainname => "PostCache", + defaulttarget => "write", + rules => [ + { + 'match' => { + 'type' => 'regex', + 'matches' => { + 'Plugin' => "^cpu$", + 'PluginInstance' => "^[0-9]+$", + }, + }, + 'targets' => [ + { + 'type' => "write", + 'attributes' => { + "Plugin" => "aggregation", + }, + }, + { + 'type' => "stop", + }, + ], + }, + ], + } +``` + ####Class: `collectd::plugin::conntrack` ```puppet diff --git a/manifests/plugin/aggregation.pp b/manifests/plugin/aggregation.pp new file mode 100644 index 000000000..953bebdc8 --- /dev/null +++ b/manifests/plugin/aggregation.pp @@ -0,0 +1,16 @@ +# +class collectd::plugin::aggregation ( + $ensure = present, + $interval = undef, + $aggregators = { }, +) { + + collectd::plugin {'aggregation': + ensure => $ensure, + interval => $interval, + } + $defaults = { + 'ensure' => $ensure + } + create_resources(collectd::plugin::aggregation::aggregator, $aggregators, $defaults) +} diff --git a/manifests/plugin/aggregation/aggregator.pp b/manifests/plugin/aggregation/aggregator.pp new file mode 100644 index 000000000..2fd087953 --- /dev/null +++ b/manifests/plugin/aggregation/aggregator.pp @@ -0,0 +1,34 @@ +# +define collectd::plugin::aggregation::aggregator ( + $ensure = 'present', + $host = undef, + $plugin = undef, + $plugininstance = undef, + $type = undef, + $typeinstance = undef, + $sethost = undef, + $setplugin = undef, + $setplugininstance = undef, + $settypeinstance = undef, + $groupby = [], + $calculatesum = undef, + $calculatenum = undef, + $calculateaverage = undef, + $calculateminimum = undef, + $calculatemaximum = undef, + $calculatestddev = undef, +) { + include collectd::params + include collectd::plugin::aggregation + + $conf_dir = $collectd::params::plugin_conf_dir + + file { "${conf_dir}/aggregator-${name}.conf": + ensure => $ensure, + mode => '0640', + owner => 'root', + group => $collectd::params::root_group, + content => template('collectd/plugin/aggregation-aggregator.conf.erb'), + notify => Service['collectd'], + } +} diff --git a/manifests/plugin/chain.pp b/manifests/plugin/chain.pp new file mode 100644 index 000000000..d1ece5e93 --- /dev/null +++ b/manifests/plugin/chain.pp @@ -0,0 +1,20 @@ +# +class collectd::plugin::chain ( + $chainname = "Main", + $ensure = 'present', + $defaulttarget = "write", + $rules = [] +) { + include collectd::params + + $conf_dir = $collectd::params::plugin_conf_dir + + file { "${conf_dir}/99-chain-${chainname}.conf": + ensure => $ensure, + mode => '0640', + owner => 'root', + group => $collectd::params::root_group, + content => template('collectd/plugin/chain.conf.erb'), + notify => Service['collectd'], + } +} diff --git a/templates/plugin/aggregation-aggregator.conf.erb b/templates/plugin/aggregation-aggregator.conf.erb new file mode 100644 index 000000000..bad586055 --- /dev/null +++ b/templates/plugin/aggregation-aggregator.conf.erb @@ -0,0 +1,55 @@ + + +<% unless @host.nil? -%> + Host "<%= @host %>" +<% end -%> +<% unless @plugin.nil? -%> + Plugin "<%= @plugin %>" +<% end -%> +<% unless @plugininstance.nil? -%> + PluginInstance "<%= @plugininstance %>" +<% end -%> +<% unless @type.nil? -%> + Type "<%= @type %>" +<% end -%> +<% unless @typeinstance.nil? -%> + TypeInstance "<%= @typeinstance %>" +<% end -%> + +<% unless @sethost.nil? -%> + SetHost "<%= @sethost %>" +<% end -%> +<% unless @setplugin.nil? -%> + SetPlugin "<%= @setplugin %>" +<% end -%> +<% unless @setplugininstance.nil? -%> + SetPluginInstance "<%= @setplugininstance %>" +<% end -%> +<% unless @settypeinstance.nil? -%> + SetTypeInstance "<%= @settypeinstance %>" +<% end -%> + +<% @groupby.each do |groupby| -%> + GroupBy "<%= groupby %>" +<% end -%> + +<% unless @calculatesum.nil? -%> + CalculateSum <%= @calculatesum %> +<% end -%> +<% unless @calculatenum.nil? -%> + CalculateNum <%= @calculatenum %> +<% end -%> +<% unless @calculateaverage.nil? -%> + CalculateAverage <%= @calculateaverage %> +<% end -%> +<% unless @calculateminimum.nil? -%> + CalculateMinimum <%= @calculateminimum %> +<% end -%> +<% unless @calculatemaximum.nil? -%> + CalculateMaximum <%= @calculatemaximum %> +<% end -%> +<% unless @calculatestddev.nil? -%> + CalculateStddev <%= @calculatestddev %> +<% end -%> + + diff --git a/templates/plugin/chain.conf.erb b/templates/plugin/chain.conf.erb new file mode 100644 index 000000000..53f0956f2 --- /dev/null +++ b/templates/plugin/chain.conf.erb @@ -0,0 +1,23 @@ +"> +<% @rules.each do |rule| -%> + + "> +<% rule['match']["matches"].each do |key, value| -%> + <%= key %> "<%= value %>" +<% end -%> + +<% rule['targets'].each do |target| -%> +<% if target['attributes'].nil? -%> + Target "<%= target['type'] %>" +<% else -%> + "> +<% target['attributes'].each do |key, value| -%> + <%= key %> "<%= value %>" +<% end -%> + +<% end -%> +<% end -%> + +<% end -%> + Target "<%= @defaulttarget %>" +