]> git.openstreetmap.org Git - chef.git/commitdiff
Label targets with appropriate instance names
authorTom Hughes <tom@compton.nu>
Wed, 16 Sep 2020 08:33:09 +0000 (09:33 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 16 Sep 2020 08:34:29 +0000 (09:34 +0100)
cookbooks/prometheus/recipes/server.rb
cookbooks/prometheus/templates/default/prometheus.yml.erb

index 5132eabdddcf3a6450e133ab7644dd4b119808c1..1e164cd1d3c751faf4d502034dc4e64a345a5532 100644 (file)
@@ -26,10 +26,10 @@ package "prometheus"
 
 clients = search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name)
 
 
 clients = search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name)
 
-prometheus_jobs = clients.each_with_object({}) do |client, jobs|
+prometheus_jobs = clients.sort_by(&:name).each_with_object({}) do |client, jobs|
   client[:prometheus][:exporters].each do |name, address|
     jobs[name] ||= []
   client[:prometheus][:exporters].each do |name, address|
     jobs[name] ||= []
-    jobs[name] << address
+    jobs[name] << { :address => address, :name => client.name }
   end
 end
 
   end
 end
 
index b00c6aaf021b8c9275712e54aef6253b60e116c1..66051b622dfc9098919246c7a3c2d6e758f11f03 100644 (file)
@@ -11,11 +11,13 @@ scrape_configs:
     static_configs:
       - targets:
           - localhost:9090
     static_configs:
       - targets:
           - localhost:9090
-<% @jobs.sort.each do |name, addresses| -%>
+<% @jobs.sort.each do |name, targets| -%>
   - job_name: <%= name %>
     static_configs:
   - job_name: <%= name %>
     static_configs:
+<% targets.each do |target| -%>
       - targets:
       - targets:
-<% addresses.sort.each do |address| -%>
-          - <%= address %>
+          - <%= target[:address] %>
+        labels:
+          instance: <%= target[:name].split(".").first %>
 <% end -%>
 <% end -%>
 <% end -%>
 <% end -%>