From 2931ebd8bf5d0a1fdaf803f28b9cf3189d1e3510 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Wed, 20 Mar 2024 14:32:46 +0100 Subject: [PATCH] updated telegraf state --- states/telegraf/config.sls | 8 +- states/telegraf/defaults.yaml | 77 ++++++++++--------- states/telegraf/service.sls | 8 +- states/telegraf/templates/telegraf.conf.j2 | 4 +- states/telegraf/templates/telegraf.service.j2 | 2 +- 5 files changed, 53 insertions(+), 46 deletions(-) diff --git a/states/telegraf/config.sls b/states/telegraf/config.sls index 82e8e7a..a8695f7 100644 --- a/states/telegraf/config.sls +++ b/states/telegraf/config.sls @@ -9,13 +9,17 @@ telegraf-config-dir: - watch_in: - service: telegraf-service +{% for cfg, value in telegraf.config.items() %} telegraf-config-file: file.managed: - - name: /etc/telegraf/telegraf.conf + - name: /etc/telegraf/{{ cfg }}.conf - source: salt://telegraf/templates/telegraf.conf.j2 - user: root - group: root - mode: 600 - template: jinja + - context: + config: {{ value }} - watch_in: - - service: telegraf-service + - service: telegraf-{{ cfg }}-service +{% endfor %} diff --git a/states/telegraf/defaults.yaml b/states/telegraf/defaults.yaml index 8a2b73b..4b4ef2b 100644 --- a/states/telegraf/defaults.yaml +++ b/states/telegraf/defaults.yaml @@ -8,41 +8,42 @@ telegraf: os: linux arch: amd64 config: - outputs: - influxdb: - urls: - - '"http://localhost:8086"' - username: username - password: password - database: telegraf - inputs: - cpu: - percpu: true - totalcpu: true - collect_cpu_time: false - report_active: false - disk: - ignore_fs: - - '"tmpfs"' - - '"devtmpfs"' - - '"devfs"' - - '"iso9660"' - - '"overlay"' - - '"aufs"' - - '"squashfs"' - - '"fuse.rclone"' - diskio: - kernel: - kernel_vmstat: - mem: - net: - netstat: - postfix: - processes: - swap: - sensors: - smart: - system: - systemd_units: - syslog: - server: "udp://:6514" + main: + outputs: + influxdb: + urls: + - '"http://localhost:8086"' + username: username + password: password + database: telegraf + inputs: + cpu: + percpu: true + totalcpu: true + collect_cpu_time: false + report_active: false + disk: + ignore_fs: + - '"tmpfs"' + - '"devtmpfs"' + - '"devfs"' + - '"iso9660"' + - '"overlay"' + - '"aufs"' + - '"squashfs"' + - '"fuse.rclone"' + diskio: + kernel: + kernel_vmstat: + mem: + net: + netstat: + postfix: + processes: + swap: + sensors: + smart: + system: + systemd_units: + syslog: + server: "udp://:6514" diff --git a/states/telegraf/service.sls b/states/telegraf/service.sls index 11e6873..4d216dc 100644 --- a/states/telegraf/service.sls +++ b/states/telegraf/service.sls @@ -2,7 +2,7 @@ {%- from "telegraf/map.jinja" import telegraf with context %} telegraf-service-file: file.managed: - - name: /etc/systemd/system/telegraf.service + - name: /etc/systemd/system/telegraf@.service - source: salt://telegraf/templates/telegraf.service.j2 - user: root - group: root @@ -10,7 +10,9 @@ telegraf-service-file: - watch_in: - service: telegraf-service -telegraf-service: +{% for cfg, value in telegraf.config.items() %} +telegraf-{{ cfg }}-service: service.running: - - name: telegraf + - name: telegraf@{{ cfg }} - enable: true +{% endfor %} diff --git a/states/telegraf/templates/telegraf.conf.j2 b/states/telegraf/templates/telegraf.conf.j2 index aad5c41..bf02b60 100644 --- a/states/telegraf/templates/telegraf.conf.j2 +++ b/states/telegraf/templates/telegraf.conf.j2 @@ -20,12 +20,12 @@ hostname = "{{ salt['grains.get']('fqdn') }}" omit_hostname = false -{% for name, value in telegraf.config.outputs.items() -%} +{% for name, value in config.outputs.items() -%} [[outputs.{{ name }}]] {{ cfg(value) }} {% endfor %} -{% for name, value in telegraf.config.inputs.items() -%} +{% for name, value in config.inputs.items() -%} [[inputs.{{ name }}]] {{ cfg(value) }} {% endfor -%} diff --git a/states/telegraf/templates/telegraf.service.j2 b/states/telegraf/templates/telegraf.service.j2 index 800276e..203f88b 100644 --- a/states/telegraf/templates/telegraf.service.j2 +++ b/states/telegraf/templates/telegraf.service.j2 @@ -7,7 +7,7 @@ After=network.target [Service] EnvironmentFile=-/etc/default/telegraf -ExecStart=/usr/local/bin/telegraf --config /etc/telegraf/telegraf.conf +ExecStart=/usr/local/bin/telegraf --config /etc/telegraf/%i.conf ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure RestartForceExitStatus=SIGPIPE