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

Added extra filtering possibilities for a plugin #113

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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