From: Tom Hughes Date: Wed, 16 Sep 2020 08:33:09 +0000 (+0100) Subject: Label targets with appropriate instance names X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/67a9b76ebb212b99bf39f98688e8d6d0e8bcbfc2?ds=inline Label targets with appropriate instance names --- diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index 5132eabdd..1e164cd1d 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -26,10 +26,10 @@ package "prometheus" 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 diff --git a/cookbooks/prometheus/templates/default/prometheus.yml.erb b/cookbooks/prometheus/templates/default/prometheus.yml.erb index b00c6aaf0..66051b622 100644 --- a/cookbooks/prometheus/templates/default/prometheus.yml.erb +++ b/cookbooks/prometheus/templates/default/prometheus.yml.erb @@ -11,11 +11,13 @@ scrape_configs: 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 -%>