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] ||= []
- jobs[name] << address
+ jobs[name] << { :address => address, :name => client.name }
end
end
static_configs:
- targets:
- localhost:9090
-<% @jobs.sort.each do |name, addresses| -%>
+<% @jobs.sort.each do |name, targets| -%>
- job_name: <%= name %>
static_configs:
+<% targets.each do |target| -%>
- targets:
-<% addresses.sort.each do |address| -%>
- - <%= address %>
+ - <%= target[:address] %>
+ labels:
+ instance: <%= target[:name].split(".").first %>
<% end -%>
<% end -%>