Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sub-configurations as needed by Aggregation Plugin. #8

Open
billclark91 opened this issue Mar 29, 2016 · 1 comment
Open

Allow sub-configurations as needed by Aggregation Plugin. #8

billclark91 opened this issue Mar 29, 2016 · 1 comment

Comments

@billclark91
Copy link

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']
}
@johnbellone
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants