]> git.openstreetmap.org Git - chef.git/commitdiff
Restart postgres exporter when the configuration changes
authorTom Hughes <tom@compton.nu>
Tue, 6 Oct 2020 18:18:20 +0000 (19:18 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 6 Oct 2020 18:18:20 +0000 (19:18 +0100)
cookbooks/postgresql/recipes/default.rb
cookbooks/prometheus/recipes/default.rb

index 6a05f34e4fad6412a3b5e8f6c4ff75b23be5366e..5dbc00c48f781ba608e9e344d866f7b72649a54c 100644 (file)
@@ -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
index 20242a84de9b89b05da97862f81afcbe9d8bff2c..82ac2ba3aead47b33712850f14fb804c3abe2a35 100644 (file)
@@ -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"