From a8261d1b13150b9ded3e6d4733ac5c381c390cdc Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 13 Mar 2022 22:51:34 +0000 Subject: [PATCH] Configure prometheus scraping for discourse servers --- cookbooks/community/recipes/default.rb | 6 ++++++ cookbooks/prometheus/recipes/server.rb | 3 +++ cookbooks/prometheus/templates/default/prometheus.yml.erb | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/cookbooks/community/recipes/default.rb b/cookbooks/community/recipes/default.rb index 5178f1617..003e69f1e 100644 --- a/cookbooks/community/recipes/default.rb +++ b/cookbooks/community/recipes/default.rb @@ -112,3 +112,9 @@ template "/etc/cron.daily/community-backup" do group "root" mode "750" end + +node.default[:prometheus][:exporters][443] = { + :name => "community", + :address => "#{node[:prometheus][:address]}:443", + :sni => "community.openstreetmap.org" +} diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index 0b6e2a0d2..6214f1858 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -229,16 +229,19 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client if exporter.is_a?(Hash) name = exporter[:name] address = exporter[:address] + sni = exporter[:sni] metric_relabel = exporter[:metric_relabel] || [] else name = key address = exporter + sni = nil metric_relabel = [] end jobs[name] ||= [] jobs[name] << { :address => address, + :sni => sni, :instance => client.name.split(".").first, :metric_relabel => metric_relabel } diff --git a/cookbooks/prometheus/templates/default/prometheus.yml.erb b/cookbooks/prometheus/templates/default/prometheus.yml.erb index d5a8debaf..9b24a4d45 100644 --- a/cookbooks/prometheus/templates/default/prometheus.yml.erb +++ b/cookbooks/prometheus/templates/default/prometheus.yml.erb @@ -57,6 +57,13 @@ scrape_configs: replacement: 127.0.0.1:9219 <% @jobs.sort.each do |name, targets| -%> - job_name: <%= name %> +<% if targets.first[:sni] -%> + tls_config: + server_name: <%= targets.first[:sni] %> + relabel_configs: + - target_label: __scheme__ + replacement: https +<% end -%> static_configs: <% targets.each do |target| -%> - targets: -- 2.39.5