From abbbdff16b1c31676eda8f7e41df8236933e9824 Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Thu, 10 Mar 2022 09:28:59 -0500 Subject: [PATCH] Telegraf configuration changes - Added shellscript for custom metrics - external IP & Temp - Bumped Telegraf version # --- default_variables.yml | 2 +- tasks/telegraf.yml | 15 ++++++++++++-- templates/scripts/service_restore.sh.j2 | 0 .../scripts/telegraf_custom_metrics.sh.j2 | 20 +++++++++++++++++++ templates/telegraf/custom_metrics.conf.j2 | 5 +++++ templates/telegraf/temperature.conf.j2 | 10 ---------- 6 files changed, 39 insertions(+), 13 deletions(-) mode change 100644 => 100755 templates/scripts/service_restore.sh.j2 create mode 100755 templates/scripts/telegraf_custom_metrics.sh.j2 create mode 100644 templates/telegraf/custom_metrics.conf.j2 delete mode 100644 templates/telegraf/temperature.conf.j2 diff --git a/default_variables.yml b/default_variables.yml index e39871a..e5eb7b7 100644 --- a/default_variables.yml +++ b/default_variables.yml @@ -5,7 +5,7 @@ influxdb_version: 1.8.4 nomad_version: 1.2.5 prometheus_verssion: 1.1.2 tdarr_installer_version: 2.00.13 -telegraf_version: 1.19.1 +telegraf_version: 1.21.4 traefik_version: "v2.6.0" # ---------------------------------- SERVICE STATIC PORT MAPPINGS diff --git a/tasks/telegraf.yml b/tasks/telegraf.yml index 6374677..0e710ea 100644 --- a/tasks/telegraf.yml +++ b/tasks/telegraf.yml @@ -163,7 +163,7 @@ mode: "644" loop: - { src: "telegraf/base_config.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.conf" } - - { src: "telegraf/temperature.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.d/temperature.conf" } + - { src: "telegraf/custom_metrics.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.d/custom_metrics.conf" } - { src: "telegraf/nomad.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.d/nomad.conf" } - { src: "telegraf/docker.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.d/docker.conf" } notify: restart_telegraf @@ -181,7 +181,18 @@ - is_cluster_leader notify: restart_telegraf - - name: Reset file ownership (macOS) + - name: Copy custom metrics script + become: true + ansible.builtin.template: + src: "scripts/telegraf_custom_metrics.sh.j2" + dest: "/usr/local/bin/telegraf_custom_metrics.sh" + mode: 0755 + owner: "{{ ansible_user_uid }}" + group: "{{ ansible_user_gid }}" + when: + - inventory_hostname != 'synology' + + - name: Reset file ownership become: true ansible.builtin.file: path: "{{ telegraph_config_location }}" diff --git a/templates/scripts/service_restore.sh.j2 b/templates/scripts/service_restore.sh.j2 old mode 100644 new mode 100755 diff --git a/templates/scripts/telegraf_custom_metrics.sh.j2 b/templates/scripts/telegraf_custom_metrics.sh.j2 new file mode 100755 index 0000000..e08ec08 --- /dev/null +++ b/templates/scripts/telegraf_custom_metrics.sh.j2 @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +EXTERNAL_IP="$(curl -s http://icanhazip.com)" + +# OS specific support +if _uname=$(command -v uname); then + case $("${_uname}" | tr '[:upper:]' '[:lower:]') in + linux*) + TEMP="$(cat /sys/class/thermal/thermal_zone0/temp)" + ;; + darwin*) + if [ -e "/usr/local/bin/osx-cpu-temp" ]; then + TEMP="$(/usr/local/bin/osx-cpu-temp | cut -c -4 | sed -E 's/\.//g')00" + fi + ;; + esac +fi + +# Print output +printf "exec ip_external=%s,cpu_temp=%s" "\"${EXTERNAL_IP}\"" "${TEMP}" diff --git a/templates/telegraf/custom_metrics.conf.j2 b/templates/telegraf/custom_metrics.conf.j2 new file mode 100644 index 0000000..77cb5b5 --- /dev/null +++ b/templates/telegraf/custom_metrics.conf.j2 @@ -0,0 +1,5 @@ +[[inputs.exec]] + commands = ["/usr/local/bin/telegraf_custom_metrics.sh"] + timeout = "5s" + name_suffix = "_homelab_metrics" + data_format = "influx" diff --git a/templates/telegraf/temperature.conf.j2 b/templates/telegraf/temperature.conf.j2 deleted file mode 100644 index 00464f6..0000000 --- a/templates/telegraf/temperature.conf.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[[inputs.exec]] -{% if 'pis' in group_names %} - commands = ["cat /sys/class/thermal/thermal_zone0/temp"] -{% elif 'macs' in group_names %} - commands = ["${HOME}/dotfiles-private/config/telegraf/cputemp.sh"] -{% endif %} - timeout = "5s" - name_suffix = "_cpu_temp" - data_format = "value" - data_type = "integer"