bloomberg/collectd-cookbook

Allow sub-configurations as needed by Aggregation Plugin.

billclark91 opened this issue · 1 comments

The collectd plugin 'aggregation' uses a sub-configurations on how to aggregate data from other plugins. In addition, the 'network' plugin uses multiple attributes in sub-configuration element.
Example:

File: /etc/collectd.d/aggregation.conf
LoadPlugin "aggregation"
<Plugin "aggregation">
    <Aggregation>
        Plugin "cpu"
        Type "cpu"
        GroupBy "Host"
        GroupBy "TypeInstance"
        CalculateNum false
        CalculateSum false
        CalculateAverage true
        CalculateMinimum false
        CalculateMaximum false
        CalculateStddev false
    </Aggregation>
</Plugin>

File: /etc/collectd.d/network.conf
LoadPlugin "network"
<Plugin "network">
    <Server "192.168.0.1" "25826">
    </Server>
</Plugin>

This can be accomplished by modifying Line:63 of plugin_config.rb to:

            elsif value.kind_of?(Hash) # rubocop:disable Style/ClassCheck
              id = value.delete('id')
              if !id.nil?
                if id.is_a?(Array)  # handle case where id is an array of attributes
                  id = id.map { |s| "\"#{s}\"" }.join(' ')
                else
                  id = "\"#{id}\""
                end
                [%(#{tabs}<#{key} #{id}>),
                 write_elements(value, indent.next),
                 %(#{tabs}</#{key}>)
                ].join("\n")
              else   # add sub-configuration elements
                [%(#{tabs}<#{key}>),
                 write_elements(value, indent.next),
                 %(#{tabs}</#{key}>)
                ].join("\n")
              end              

And attributes using:

default['collectd_plugins']['aggregation']['aggregation'] = {
    'plugin' => 'cpu',
    'type' => 'cpu',
    'group_by' => %w(Host TypeInstance),
    'calculate_num' => false,
    'calculate_sum' => false,
    'calculate_average' => true,
    'calculate_minimum' => false,
    'calculate_maximum' => false,   
    'calculate_stddev' => false
}

default['collectd_plugins']['network']['server'] = {
    'id' => ['192.168.0.1', '25826']
}

Can you submit a pull-request with tests? It'll be much easier for us to review. Thanks!