From 7db15d9c63c4be34c376bd42daf8bc7d18f08389 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 1 Apr 2023 22:32:42 +0200 Subject: [PATCH] prometheus_node: cleanup --- roles/prometheus_node/files/apt.sh | 32 ------------- .../prometheus-node-exporter-apt.service | 7 --- .../files/prometheus-node-exporter-apt.timer | 9 ---- roles/prometheus_node/handlers/main.yml | 5 -- roles/prometheus_node/tasks/main.yml | 47 ++++--------------- 5 files changed, 9 insertions(+), 91 deletions(-) delete mode 100644 roles/prometheus_node/files/apt.sh delete mode 100644 roles/prometheus_node/files/prometheus-node-exporter-apt.service delete mode 100644 roles/prometheus_node/files/prometheus-node-exporter-apt.timer delete mode 100644 roles/prometheus_node/handlers/main.yml diff --git a/roles/prometheus_node/files/apt.sh b/roles/prometheus_node/files/apt.sh deleted file mode 100644 index b61e72f..0000000 --- a/roles/prometheus_node/files/apt.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# Description: Expose metrics from apt updates. -# -# Author: Ben Kochie - -upgrades="$(/usr/bin/apt-get --just-print dist-upgrade \ - | /usr/bin/awk -F'[()]' \ - '/^Inst/ { sub("^[^ ]+ ", "", $2); gsub(" ","",$2); - sub("\\[", " ", $2); sub("\\]", "", $2); print $2 }' \ - | /usr/bin/sort \ - | /usr/bin/uniq -c \ - | awk '{ gsub(/\\\\/, "\\\\", $2); gsub(/\"/, "\\\"", $2); - gsub(/\[/, "", $3); gsub(/\]/, "", $3); - print "apt_upgrades_pending{origin=\"" $2 "\",arch=\"" $NF "\"} " $1}' -)" - -echo '# HELP apt_upgrades_pending Apt package pending updates by origin.' -echo '# TYPE apt_upgrades_pending gauge' -if [[ -n "${upgrades}" ]] ; then - echo "${upgrades}" -else - echo 'apt_upgrades_pending{origin="",arch=""} 0' -fi - -echo '# HELP node_reboot_required Node reboot is required for software updates.' -echo '# TYPE node_reboot_required gauge' -if [[ -f '/run/reboot-required' ]] ; then - echo 'node_reboot_required 1' -else - echo 'node_reboot_required 0' -fi diff --git a/roles/prometheus_node/files/prometheus-node-exporter-apt.service b/roles/prometheus_node/files/prometheus-node-exporter-apt.service deleted file mode 100644 index 63c901d..0000000 --- a/roles/prometheus_node/files/prometheus-node-exporter-apt.service +++ /dev/null @@ -1,7 +0,0 @@ -[Unit] -Description=Collect apt metrics for prometheus-node-exporter - -[Service] -Type=oneshot -Environment=TMPDIR=/var/lib/prometheus/node-exporter -ExecStart=/bin/bash -c "/usr/share/prometheus-node-exporter/apt.sh | sponge /var/lib/prometheus/node-exporter/apt.prom" diff --git a/roles/prometheus_node/files/prometheus-node-exporter-apt.timer b/roles/prometheus_node/files/prometheus-node-exporter-apt.timer deleted file mode 100644 index 6ed4b45..0000000 --- a/roles/prometheus_node/files/prometheus-node-exporter-apt.timer +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Run apt metrics collection every 15 minutes - -[Timer] -OnBootSec=0 -OnUnitActiveSec=15min - -[Install] -WantedBy=timers.target diff --git a/roles/prometheus_node/handlers/main.yml b/roles/prometheus_node/handlers/main.yml deleted file mode 100644 index b4b64a4..0000000 --- a/roles/prometheus_node/handlers/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Restart prometheus-node-exporter - service: - name: prometheus-node-exporter - state: restarted diff --git a/roles/prometheus_node/tasks/main.yml b/roles/prometheus_node/tasks/main.yml index dea8596..087a698 100644 --- a/roles/prometheus_node/tasks/main.yml +++ b/roles/prometheus_node/tasks/main.yml @@ -1,49 +1,20 @@ --- -- name: Install Prometheus node-exporter +- name: Install prometheus-node-exporter apt: - update_cache: true - name: prometheus-node-exporter + name: + - prometheus-node-exporter + - prometheus-node-exporter-collectors install_recommends: false # Do not install smartmontools - register: apt_result - retries: 3 - until: apt_result is succeeded - when: - - ansible_lsb.codename != 'stretch' -# Prometheus 2 node is in stretch-backports -- name: Install Prometheus node-exporter (stretch-backports) +- name: Install smartmontools apt: - update_cache: true - name: prometheus-node-exporter - install_recommends: false - default_release: stretch-backports - register: apt_result - retries: 3 - until: apt_result is succeeded + name: smartmontools when: - - ansible_lsb.codename == 'stretch' + - "ansible_virtualization_role == 'host'" -- name: Install Prometheus node-exporter collectors (bullseye) - apt: - update_cache: true - name: prometheus-node-exporter-collectors - install_recommends: false - register: apt_result - retries: 3 - until: apt_result is succeeded - when: ansible_facts['lsb']['codename'] == 'bullseye' - -- name: Activate prometheus-node-exporter service +- name: Enable prometheus-node-exporter systemd: name: prometheus-node-exporter enabled: true state: started - -# Doesn't work on Debian Stretch with the old prometheus package -- name: Make Prometheus node-exporter listen on adm only - lineinfile: - path: /etc/default/prometheus-node-exporter - regexp: '^ARGS=' - line: | - ARGS="--web.listen-address={{ ansible_hostname }}.adm.auro.re:9100" - notify: Restart prometheus-node-exporter +...