]> git.openstreetmap.org Git - chef.git/commitdiff
Group prometheus josb by exporter instead of client
authorTom Hughes <tom@compton.nu>
Tue, 15 Sep 2020 18:04:32 +0000 (18:04 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 15 Sep 2020 18:15:32 +0000 (19:15 +0100)
cookbooks/prometheus/recipes/server.rb
cookbooks/prometheus/templates/default/prometheus.yml.erb

index f82fe04bf349d66691f7f0c886fe753073e03c89..297070b338952ac533224b8c483c2d8d2a8c7009 100644 (file)
@@ -21,12 +21,19 @@ package "prometheus"
 
 clients = search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name)
 
+prometheus_jobs = clients.each_with_object({}) do |client, jobs|
+  client[:prometheus][:exporters].each do |name, address|
+    jobs[name] ||= []
+    jobs[name] << address
+  end
+end
+
 template "/etc/prometheus/prometheus.yml" do
   source "prometheus.yml.erb"
   owner "root"
   group "root"
   mode "644"
-  variables :clients => clients
+  variables :jobs => prometheus_jobs
 end
 
 service "prometheus" do
index 60345ef5258ee95577605a9b4901843154413e7c..b00c6aaf021b8c9275712e54aef6253b60e116c1 100644 (file)
@@ -11,11 +11,11 @@ scrape_configs:
     static_configs:
       - targets:
           - localhost:9090
-<% @clients.each do |client| -%>
-  - job_name: <%= client.name %>
+<% @jobs.sort.each do |name, addresses| -%>
+  - job_name: <%= name %>
     static_configs:
       - targets:
-<% client[:prometheus][:exporters].sort.each do |_,address| -%>
+<% addresses.sort.each do |address| -%>
           - <%= address %>
 <% end -%>
 <% end -%>