Skip to content

Commit

Permalink
Merge pull request #113 from dj-wasabi/add-sub-configuration
Browse files Browse the repository at this point in the history
Added extra filtering possibilities for a plugin
  • Loading branch information
Werner Dijkerman authored Feb 4, 2020
2 parents 0006d91 + a55ef0b commit 67253f5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- [Example Docker configuration](#example-docker-configuration)
* [Windows specific Variables](#windows-specific-variables)
* [Extra information](#extra-information-1)
+ [telegraf_plugins_default](#telegraf-plugins-default)
+ [telegraf_plugins_extra](#telegraf-plugins-extra)
* [Dependencies](#dependencies)
* [Example Playbook](#example-playbook)
* [Contributors](#contributors)
Expand Down Expand Up @@ -238,6 +240,8 @@ There are two properties which are similar, but are used differently. Those are:
* `telegraf_plugins_default`
* `telegraf_plugins_extra`

### telegraf_plugins_default

With the property `telegraf_plugins_default` it is set to use the default set of Telegraf plugins. You could override it with more plugins, which should be enabled at default.

telegraf_plugins_default:
Expand All @@ -253,6 +257,8 @@ With the property `telegraf_plugins_default` it is set to use the default set of

Every telegraf agent has these as a default configuration.

### telegraf_plugins_extra

The 2nd parameter `telegraf_plugins_extra` can be used to add plugins specific to the servers goal. It is a hash instead of a list, so that you can merge values from multiple var files together. Following is an example for using this parameter for MySQL database servers:

cat group_vars/mysql_database
Expand All @@ -269,6 +275,8 @@ Telegraf plugin options:
* `tagpass`: (added in Telegraf 0.1.5) tag names and arrays of strings that are used to filter metrics by the current plugin. Each string in the array is tested as an exact match against the tag name, and if it matches the metric is emitted.
* `tagdrop`: (added in Telegraf 0.1.5) The inverse of tagpass. If a tag matches, the metric is not emitted. This is tested on metrics that have passed the tagpass test.
* `interval`: How often to gather this metric. Normal plugins use a single global interval, but if one particular plugin should be run less or more often, you can configure that here.
* `filter.name`: Like when there is an extra filter that needs to be configured, like `grok` for a `logparser` plugin.
* `filter.config`: The extra configuration for the - in the `filter.name` example - `grok` filter. (See example below)

An example might look like this:

Expand All @@ -292,6 +300,19 @@ telegraf_processors:
- dest = "LogLevel"
```

When you want to make use of the `grok` filter for the logparser:

telegraf_plugins_extra:
logparser:
plugin: logparser
config:
- files = ["/var/log/messages"]
- from_beginning = false
filter:
name: grok
config:
- patterns = ["invoked oom-killer"]

## Dependencies

No dependencies
Expand Down
14 changes: 8 additions & 6 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ provisioner:
- database = "telegraf"
- precision = "s"
telegraf_plugins_extra:
percpu-usage:
plugin: cpu
logparser:
plugin: logparser
config:
- percpu = true
- totalcpu = false
- name_override = "percpu_usage"
- fielddrop = ["cpu_time*"]
- files = ["/var/log/messages"]
- from_beginning = false
filter:
name: grok
config:
- patterns = ["invoked oom-killer"]

scenario:
name: default
Expand Down
6 changes: 3 additions & 3 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def test_telegraf_dot_d_dir(host):


def test_telegraf_dot_d(host):
telegraf = host.file("/etc/telegraf/telegraf.d/percpu-usage.conf")
telegraf = host.file("/etc/telegraf/telegraf.d/logparser.conf")
assert telegraf.user == "telegraf"
assert telegraf.group == "telegraf"
assert telegraf.mode == 0o640
assert telegraf.contains('[[inputs.cpu]]')
assert telegraf.contains('totalcpu = false')
assert telegraf.contains('[[inputs.logparser]]')
assert telegraf.contains('from_beginning = false')


def test_telegraf_package(host):
Expand Down
10 changes: 10 additions & 0 deletions templates/telegraf-extra-plugin.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
{{ items }}
{% endfor %}
{% endif %}
{% if item.value.filter is defined %}
{% if item.value.filter.name is defined %}
[inputs.{{ item.value.plugin | default(item.key) }}.{{ item.value.filter.name | default("grok") }}]
{% if item.value.filter.config is defined and item.value.filter.config is iterable %}
{% for items in item.value.filter.config %}
{{ items }}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
{% if item.value.objects is defined and item.value.objects is iterable %}
{% for object in item.value.objects %}
[[inputs.{{ item.value.plugin | default(item.key) }}.object]]
Expand Down

0 comments on commit 67253f5

Please sign in to comment.