Skip to content
Snippets Groups Projects
Verified Commit 5ebe07a4 authored by Julian's avatar Julian
Browse files

Only reload prometheus/alertmanager if config changes

Previously prometheus/alertmanager were unconditionally reloaded every 10
minutes. Reloading alertmanager when it is about to deliver an alert
notification seems to make it account successfull notification deliveries as
failed, increasing alertmanager_notifications_failed_total. So reloading every
10 minutes caused spurious AlertmanagerNotifications alerts in our setup.

Also config updates are now atomic regardless of whether /tmp is a tmpfs.
parent 6cb9d481
Branches
Tags
No related merge requests found
#!/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
tmpfile=`mktemp`
( (
cat /etc/prometheus/conf.d/*.conf cat /etc/prometheus/conf.d/*.conf
...@@ -13,9 +11,14 @@ echo " alertmanagers:" ...@@ -13,9 +11,14 @@ echo " alertmanagers:"
echo "scrape_configs:" echo "scrape_configs:"
cat /etc/prometheus/conf.d/scrape_configs/*.conf cat /etc/prometheus/conf.d/scrape_configs/*.conf
) > $tmpfile ) > /etc/prometheus/prometheus.yml.new
chmod 0644 /etc/prometheus/prometheus.yml.new
chmod 0644 $tmpfile if ! diff -q /etc/prometheus/prometheus.yml.new /etc/prometheus/prometheus.yml > /dev/null; then
mv $tmpfile /etc/prometheus/prometheus.yml mv /etc/prometheus/prometheus.yml.new /etc/prometheus/prometheus.yml
/usr/bin/systemctl reload prometheus /usr/bin/systemctl reload prometheus
/usr/bin/systemctl reload prometheus-alertmanager || true /usr/bin/systemctl reload prometheus-alertmanager || true
else
rm -f /etc/prometheus/prometheus.yml.new
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment