diff --git a/roles/telegraf/handlers/main.yaml b/roles/telegraf/handlers/main.yaml new file mode 100644 index 0000000..f471849 --- /dev/null +++ b/roles/telegraf/handlers/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Restart telegraf + ansible.builtin.service: + name: telegraf.service + state: restarted diff --git a/roles/telegraf/tasks/main.yaml b/roles/telegraf/tasks/main.yaml index d45b2b0..b521fd0 100644 --- a/roles/telegraf/tasks/main.yaml +++ b/roles/telegraf/tasks/main.yaml @@ -1,49 +1,17 @@ --- -- name: Install required system packages - ansible.builtin.apt: - pkg: - - apt-transport-https - - ca-certificates - - gnupg - - curl - state: latest - update_cache: true - -- name: Add Influxdata GPG apt key - ansible.builtin.apt_key: - url: "https://repos.influxdata.com/influxdata-archive.key" - state: present - -- name: Add Influxdata repository - ansible.builtin.apt_repository: - repo: deb https://repos.influxdata.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable - state: present - filename: "telegraf" - -- name: Install telegraf package - ansible.builtin.apt: - pkg: - - telegraf - state: latest - update_cache: true - -- name: Gather the package facts - ansible.builtin.package_facts: - manager: auto - - name: Add telegraf to docker group ansible.builtin.user: name: telegraf groups: docker append: true - when: "'docker-ce' in ansible_facts.packages" + when: "docker is defined and docker == 'true'" + notify: + - Restart telegraf -- name: Enable telegraf service - ansible.builtin.service: - name: telegraf - enabled: true - -- name: Stop telegraf service (configure it before starting) - ansible.builtin.service: - name: telegraf - state: stopped +- name: Deploy configuration file + ansible.builtin.template: + src: telegraf.conf.j2 + dest: /etc/telegraf/telegraf.conf + mode: "644" + notify: + - Restart telegraf diff --git a/telegraf.yaml b/telegraf.yaml deleted file mode 100644 index 4ac73ac..0000000 --- a/telegraf.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: "Install telegraf on debian." - hosts: telegraf - roles: - - telegraf diff --git a/templates/telegraf.conf.j2 b/templates/telegraf.conf.j2 new file mode 100644 index 0000000..68425a8 --- /dev/null +++ b/templates/telegraf.conf.j2 @@ -0,0 +1,35 @@ +[agent] + hostname = "{{ansible_hostname}}" + flush_interval = "15s" + interval = "15s" + +[[inputs.cpu]] + percpu = true + totalcpu = true + collect_cpu_time = false + report_active = false +[[inputs.disk]] + ignore_fs = ["tmpfs", "devtmpfs", "devfs"] +[[inputs.diskio]] +[[inputs.mem]] +[[inputs.netstat]] +[[inputs.net]] + ignore_protocol_stats = true +[[inputs.system]] +[[inputs.swap]] +[[inputs.processes]] +[[inputs.kernel]] + +{% if docker == true %} +[[inputs.docker]] + endpoint = "unix:///var/run/docker.sock" + container_names = [] + timeout = "5s" + total = false +{% endif %} + +[[outputs.influxdb_v2]] + urls = ["https://influxdb.louis-vallat.dev"] + organization = "louis-vallat.dev" + bucket = "telegraf" + token = "{{telegraf_token}}"