]> git.openstreetmap.org Git - chef.git/commitdiff
Fix prometheus monitoring of multiple postgres instances
authorTom Hughes <tom@compton.nu>
Thu, 21 Jan 2021 12:24:05 +0000 (12:24 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 21 Jan 2021 12:28:26 +0000 (12:28 +0000)
cookbooks/postgresql/recipes/default.rb

index b192080fb00a7e5f3a3806bb00540ca65ed5e093..47ec3e80bfffee64cc580f0b8e09747adc339fa6 100644 (file)
@@ -154,8 +154,8 @@ clusters.each do |name, details|
   end
 end
 
-ports = clusters.collect do |_, details|
-  details[:port]
+uris = clusters.collect do |_, details|
+  "postgres@:#{details[:port]}/postgres?host=/run/postgresql"
 end
 
 template "/etc/prometheus/exporters/postgres_queries.yml" do
@@ -169,7 +169,7 @@ prometheus_exporter "postgres" do
   port 9187
   user "postgres"
   options "--extend.query-path=/etc/prometheus/exporters/postgres_queries.yml"
-  environment "DATA_SOURCE_URI" => "postgres@:#{ports.join(',:')}/postgres?host=/run/postgresql",
+  environment "DATA_SOURCE_URI" => uris.sort.uniq.first,
               "PG_EXPORTER_AUTO_DISCOVER_DATABASES" => "true",
               "PG_EXPORTER_EXCLUDE_DATABASES" => "postgres,template0,template1"
   subscribes :restart, "template[/etc/prometheus/exporters/postgres_queries.yml]"