From 5f87e80390086757b4dbbf810e4417225751d7f9 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 6 Oct 2020 19:18:20 +0100 Subject: [PATCH] Restart postgres exporter when the configuration changes --- cookbooks/postgresql/recipes/default.rb | 9 +++++++-- cookbooks/prometheus/recipes/default.rb | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cookbooks/postgresql/recipes/default.rb b/cookbooks/postgresql/recipes/default.rb index 6a05f34e4..5dbc00c48 100644 --- a/cookbooks/postgresql/recipes/default.rb +++ b/cookbooks/postgresql/recipes/default.rb @@ -158,7 +158,11 @@ ports = clusters.collect do |_, details| "port=#{details[:port]}" end -template "/etc/prometheus/collectors/postgres_queries.yml" do +file "/etc/prometheus/collectors/postgres_queries.yml" do + action :delete +end + +template "/etc/prometheus/exporters/postgres_queries.yml" do source "postgres_queries.yml.erb" owner "root" group "root" @@ -168,7 +172,8 @@ end prometheus_exporter "postgres" do port 9187 user "postgres" - options "--extend.query-path=/etc/prometheus/collectors/postgres_queries.yml" + options "--extend.query-path=/etc/prometheus/exporters/postgres_queries.yml" environment "DATA_SOURCE_NAME" => "user=postgres host=/run/postgresql #{ports.join(',')}", "PG_EXPORTER_EXCLUDE_DATABASES" => "postgres,template0,template1" + subscribes :restart, "template[/etc/prometheus/exporters/postgres_queries.yml]" end diff --git a/cookbooks/prometheus/recipes/default.rb b/cookbooks/prometheus/recipes/default.rb index 20242a84d..82ac2ba3a 100644 --- a/cookbooks/prometheus/recipes/default.rb +++ b/cookbooks/prometheus/recipes/default.rb @@ -64,6 +64,13 @@ directory "/etc/prometheus/collectors" do recursive true end +directory "/etc/prometheus/exporters" do + owner "root" + group "root" + mode "755" + recursive true +end + directory "/var/lib/prometheus/node-exporter" do owner "root" group "adm" -- 2.43.2