From: Tom Hughes Date: Mon, 3 Jul 2023 23:17:23 +0000 (+0100) Subject: Add pool label to phpfpm exporters to avoid duplicate metrics X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/32bd9dc80026c2613f386669b3d1eea358052ddb Add pool label to phpfpm exporters to avoid duplicate metrics --- diff --git a/cookbooks/php/resources/fpm.rb b/cookbooks/php/resources/fpm.rb index 3ac51d0b7..13c973580 100644 --- a/cookbooks/php/resources/fpm.rb +++ b/cookbooks/php/resources/fpm.rb @@ -58,6 +58,7 @@ action :create do group "www-data" command "server" options "--phpfpm.scrape-uri=#{scrape_uri} --phpfpm.fix-process-count" + labels "pool" => new_resource.pool end else prometheus_exporter "phpfpm" do diff --git a/cookbooks/prometheus/resources/exporter.rb b/cookbooks/prometheus/resources/exporter.rb index 66dcd2b29..e2d8ca7da 100644 --- a/cookbooks/prometheus/resources/exporter.rb +++ b/cookbooks/prometheus/resources/exporter.rb @@ -42,6 +42,7 @@ property :restrict_address_families, [String, Array] property :remove_ipc, [true, false] property :system_call_filter, [String, Array] property :service, :kind_of => String +property :labels, :kind_of => Hash, :default => {} property :scrape_interval, :kind_of => String property :scrape_timeout, :kind_of => String property :metric_relabel, :kind_of => Array @@ -91,6 +92,7 @@ action :create do node.default[:prometheus][:exporters][new_resource.port] = { :name => new_resource.exporter, :address => listen_address, + :labels => new_resource.labels, :scrape_interval => new_resource.scrape_interval, :scrape_timeout => new_resource.scrape_timeout, :metric_relabel => new_resource.metric_relabel diff --git a/cookbooks/prometheus/templates/default/prometheus.yml.erb b/cookbooks/prometheus/templates/default/prometheus.yml.erb index 9c163f265..922fa123b 100644 --- a/cookbooks/prometheus/templates/default/prometheus.yml.erb +++ b/cookbooks/prometheus/templates/default/prometheus.yml.erb @@ -72,6 +72,9 @@ scrape_configs: - "<%= target[:address] %>" labels: instance: <%= target[:instance] %> +<% Hash(target[:labels]).sort.each do |name, value| -%> + <%= name %>: <%= value %> +<% end -%> <% end -%> metric_relabel_configs: <% targets.each do |target| -%>