mirror of
https://github.com/dj-wasabi/ansible-telegraf.git
synced 2025-07-17 08:46:37 +00:00
Merge pull request #113 from dj-wasabi/add-sub-configuration
Added extra filtering possibilities for a plugin
This commit is contained in:
21
README.md
21
README.md
@ -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)
|
||||
@ -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:
|
||||
@ -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
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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]]
|
||||
|
Reference in New Issue
Block a user