Skip to content

Installing and configuring Telegraf via Ansible for RedHat/Debian/Ubuntu

License

Notifications You must be signed in to change notification settings

hpc-unibe-ch/ansible-role-telegraf

 
 

Repository files navigation

ansible-role-telegraf

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.

Requirements

No prerequisites necessary at the moment.

Role Variables

The most common variables are listed below, along with default values. See also defaults/main.yml for a complete list.

telegraf_state

telegraf_state: present

Specify whether telegraf should be present or absent on the system.

ssh_manage_motd_file

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

telegraf_enabled: true

Specifies whether the telegraf agent service is to be enabled on the system

telegraf_agent_version

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.

telegraf_agent_output

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"]

Extra information

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:
  - 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.

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
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, like grok for a logparser plugin.
  • filter.config: The extra configuration for the - in the filter.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" ]

Example Playbook

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

Compatibility

This role has been written for and tested on and is therefore compatible with:

  • Rocky-9
  • Ubuntu-22.04

Dependencies

This role has no dependencies.

License

MIT

Author Information

The role was created in 2024 by the IT-Services Office of the University of Bern based on this repository: dj-wasabi.telegraf

About

Installing and configuring Telegraf via Ansible for RedHat/Debian/Ubuntu

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jinja 100.0%