An Ansible role that installs and configures telegraf. Currently the role has the following features:
- Install telegraf agent
- Manage telegraf config settings in
/etc/telegraf/telegraf.conf
, see role variables - Completely remove telegraf agent
Note
This role is a stripped down fork of dj-wasabi.telegraf to fit the needs of our site and add the feature to remove the telegraf agent if it's no longer required on a system.
No prerequisites necessary at the moment.
The most common variables are listed below, along with default values. See also
defaults/main.yml
for a complete list.
telegraf_state: present
Specify whether telegraf should be present or absent on the system.
ssh_manage_motd_file: false
Specifies whether to craft a custom /etc/motd
file showing some system
informations like OS name/version, IP addresses and CPU and memory information.
If set to false, the file /etc/motd
is not modified, if set to true the file
is managed an updated if needed.
telegraf_enabled: true
Specifies whether the telegraf agent service is to be enabled on the system
telegraf_agent_version: 1.32.0
Specifying the version to be installed
If telegraf_agent_package_state
is set to latest
, then this property and value is ignored.
Specifying an output. The default is set to localhost, you'll have to specify the correct influxdb server:
telegraf_agent_output:
- type: influxdb
config:
- urls = ["http://localhost:8086"]
- database = "telegraf"
tagpass:
- cpu = ["cpu0"]
There are two properties which are similar, but are used differently. Those are:
telegraf_plugins_default
telegraf_plugins_extra
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:
- plugin: cpu
config:
- percpu = true
- plugin: disk
- plugin: io
- plugin: mem
- plugin: system
- plugin: swap
- plugin: netstat
Every telegraf agent has these as a default configuration.
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
telegraf_plugins_extra:
mysql:
config:
- servers = ["root:{{ mysql_root_password }}@tcp(localhost:3306)/"]
There is an option to delete extra-plugin files in /etc/telegraf/telegraf.d if they weren't generated by this playbook with telegraf_plugins_extra_exclusive
variable.
Telegraf plugin options:
tags
An k/v tags to apply to a specific input's measurements. Can be used on any stage for better filtering for example in outputs.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, likegrok
for alogparser
plugin.filter.config
: The extra configuration for the - in thefilter.name
example -grok
filter. (See example below)sub_inputs
: If the input requires other sub inputs, you can add them here (see example below).
An example might look like this:
telegraf_plugins_default:
- plugin: disk
interval: 12
tags:
- diskmetrics = "true"
tagpass:
- fstype = [ "ext4", "xfs" ]
- path = [ "/opt", "/home" ]
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- role: ubelix.telegraf
This role has been written for and tested on and is therefore compatible with:
- Rocky-9
- Ubuntu-22.04
This role has no dependencies.
MIT
The role was created in 2024 by the IT-Services Office of the University of Bern based on this repository: dj-wasabi.telegraf