From b05a9a0ad46bea8876ef5a7a6ac310a7e92cd9ab Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Wed, 18 Aug 2021 07:10:35 +0200 Subject: [PATCH] updated telegraf state --- states/telegraf/config.sls | 3 ++ states/telegraf/defaults.yaml | 86 ++++++++++++-------------------- states/telegraf/telegraf.conf.j2 | 28 ++++++----- 3 files changed, 49 insertions(+), 68 deletions(-) diff --git a/states/telegraf/config.sls b/states/telegraf/config.sls index 9155a97..af3ecdb 100644 --- a/states/telegraf/config.sls +++ b/states/telegraf/config.sls @@ -3,6 +3,9 @@ telegraf-config-dir: file.directory: - name: /etc/telegraf + - user: root + - group: root + - mode: 700 - watch_in: - service: telegraf-service diff --git a/states/telegraf/defaults.yaml b/states/telegraf/defaults.yaml index 6ca83f9..2431177 100644 --- a/states/telegraf/defaults.yaml +++ b/states/telegraf/defaults.yaml @@ -5,82 +5,58 @@ telegraf: install_dir: /usr/local/apps mirror: https://dl.influxdata.com/telegraf/releases version: 1.13.3 - influxdb_urls: - - '"http://localhost:8086"' - influxdb_username: username - influxdb_password: password - influxdb_database: telegraf os: linux arch: amd64 config: outputs: + influxdb: + urls: + - '"http://localhost:8086"' + username: username + password: password + database: telegraf inputs: cpu: - name: "cpu" - params: - percpu: true - totalcpu: true - collect_cpu_time: false - report_active: false + percpu: true + totalcpu: true + collect_cpu_time: false + report_active: false disk: - name: "disk" - params: - ignore_fs: - - '"tmpfs"' - - '"devtmpfs"' - - '"devfs"' - - '"iso9660"' - - '"overlay"' - - '"aufs"' - - '"squashfs"' + ignore_fs: + - '"tmpfs"' + - '"devtmpfs"' + - '"devfs"' + - '"iso9660"' + - '"overlay"' + - '"aufs"' + - '"squashfs"' diskio: - name: "diskio" httpjson: - name: "httpjson" - params: - name: "ipinfo" - interval: "15m" - servers: - - '"https://ipinfo.io"' - response_timeout: "5s" - method: "GET" - tag_keys: - - '"ip"' + name: "ipinfo" + interval: "15m" + servers: + - '"https://ipinfo.io"' + response_timeout: "5s" + method: "GET" + tag_keys: + - '"ip"' kernel: - name: "kernel" kernel_vmstat: - name: "kernel_vmstat" mem: - name: "mem" net: - name: "net" netstat: - name: "netstat" nginx: - name: "nginx" - params: - urls: - - '"http://localhost/status"' - response_timeout: "5s" + urls: + - '"http://localhost/status"' + response_timeout: "5s" ntpq: - name: "ntpq" - params: - dns_lookup: true + dns_lookup: true postfix: - name: "postfix" processes: - name: "processes" swap: - name: "swap" sensors: - name: "sensors" smart: - name: "smart" system: - name: "system" systemd_units: - name: "systemd_units" syslog: - name: "syslog" - params: - server: "udp://:6514" + server: "udp://:6514" diff --git a/states/telegraf/telegraf.conf.j2 b/states/telegraf/telegraf.conf.j2 index 49f818c..3a777f4 100644 --- a/states/telegraf/telegraf.conf.j2 +++ b/states/telegraf/telegraf.conf.j2 @@ -1,6 +1,5 @@ ## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} {%- from "telegraf/map.jinja" import telegraf with context %} - [global_tags] [agent] interval = "1m" @@ -14,17 +13,20 @@ hostname = "{{ salt['grains.get']('fqdn') }}" omit_hostname = false -[[outputs.influxdb]] - urls = [{{ telegraf.influxdb_urls|join(",") }}] - username = "{{ telegraf.influxdb_username }}" - password = "{{ telegraf.influxdb_password }}" - database = "{{ telegraf.influxdb_database }}" - -{% for name, value in telegraf.config.inputs.items() %} -[[inputs.{{ name }}]] -{%- if value['params'] is defined %} -{%- for paramname, paramvalue in value['params'].items() %} - {{ paramname }} = {% if paramvalue is sameas True or paramvalue is sameas False %}{{ paramvalue|string|lower }}{% elif paramvalue is iterable and paramvalue is not string %}[{{ paramvalue|join(",") }}]{% else %}"{{ paramvalue }}"{% endif %} -{%- endfor %} +{% for name, value in telegraf.config.outputs.items() -%} +[[outputs.{{ name }}]] +{% if value is not none -%} +{% for paramname, paramvalue in value.items() -%} +{{ ' '}}{{ paramname }} = {% if paramvalue is sameas True or paramvalue is sameas False %}{{ paramvalue|string|lower }}{% elif paramvalue is iterable and paramvalue is not string %}[{{ paramvalue|join(",") }}]{% else %}"{{ paramvalue }}"{% endif %} +{% endfor %} {%- endif %} {% endfor %} + +{% for name, value in telegraf.config.inputs.items() -%} +[[inputs.{{ name }}]] +{% if value is not none -%} +{% for paramname, paramvalue in value.items() -%} +{{ ' ' }}{{ paramname }} = {% if paramvalue is sameas True or paramvalue is sameas False %}{{ paramvalue|string|lower }}{% elif paramvalue is iterable and paramvalue is not string %}[{{ paramvalue|join(",") }}]{% else %}"{{ paramvalue }}"{% endif %} +{% endfor %} +{%- endif %} +{% endfor -%}