From 778dafe1b60675abedacec30bbbec1e174fec5b0 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 24 Jan 2021 11:59:16 +0000 Subject: [PATCH] Proxy requests to the prometheus and alertmanager web UIs --- cookbooks/prometheus/recipes/server.rb | 16 ++++++++++++++++ .../prometheus/templates/default/apache.erb | 3 +++ .../templates/default/default.alertmanager.erb | 3 +++ .../templates/default/default.prometheus.erb | 3 +++ .../templates/default/prometheus.yml.erb | 5 ++++- 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cookbooks/prometheus/templates/default/default.alertmanager.erb create mode 100644 cookbooks/prometheus/templates/default/default.prometheus.erb diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index 9acc28671..d069cd8e7 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -169,6 +169,13 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client end end +template "/etc/default/prometheus" do + source "default.prometheus.erb" + owner "root" + group "root" + mode "644" +end + template "/etc/prometheus/prometheus.yml" do source "prometheus.yml.erb" owner "root" @@ -179,9 +186,17 @@ end service "prometheus" do action [:enable, :start] + subscribes :restart, "template[/etc/default/prometheus]" subscribes :reload, "template[/etc/prometheus/prometheus.yml]" end +template "/etc/default/prometheus-alertmanager" do + source "default.alertmanager.erb" + owner "root" + group "root" + mode "644" +end + template "/etc/prometheus/alertmanager.yml" do source "alertmanager.yml.erb" owner "root" @@ -191,6 +206,7 @@ end service "prometheus-alertmanager" do action [:enable, :start] + subscribes :restart, "template[/etc/default/prometheus-alertmanager]" subscribes :reload, "template[/etc/prometheus/alertmanager.yml]" end diff --git a/cookbooks/prometheus/templates/default/apache.erb b/cookbooks/prometheus/templates/default/apache.erb index b4c7c55ac..00760ed43 100644 --- a/cookbooks/prometheus/templates/default/apache.erb +++ b/cookbooks/prometheus/templates/default/apache.erb @@ -23,6 +23,9 @@ SSLCertificateFile /etc/ssl/certs/prometheus.openstreetmap.org.pem SSLCertificateKeyFile /etc/ssl/private/prometheus.openstreetmap.org.key + ProxyPass /prometheus http://localhost:9090/prometheus + Redirect 403 /alertmanager/api + ProxyPass /alertmanager http://localhost:9093/alertmanager ProxyPass / http://localhost:3000/ ProxyPreserveHost on diff --git a/cookbooks/prometheus/templates/default/default.alertmanager.erb b/cookbooks/prometheus/templates/default/default.alertmanager.erb new file mode 100644 index 000000000..42d6e3a3d --- /dev/null +++ b/cookbooks/prometheus/templates/default/default.alertmanager.erb @@ -0,0 +1,3 @@ +# DO NOT EDIT - This file is being maintained by Chef + +ARGS="--web.external-url=https://prometheus.openstreetmap.org/alertmanager" diff --git a/cookbooks/prometheus/templates/default/default.prometheus.erb b/cookbooks/prometheus/templates/default/default.prometheus.erb new file mode 100644 index 000000000..451faa78c --- /dev/null +++ b/cookbooks/prometheus/templates/default/default.prometheus.erb @@ -0,0 +1,3 @@ +# DO NOT EDIT - This file is being maintained by Chef + +ARGS="--web.external-url=https://prometheus.openstreetmap.org/prometheus" diff --git a/cookbooks/prometheus/templates/default/prometheus.yml.erb b/cookbooks/prometheus/templates/default/prometheus.yml.erb index b44654463..b7a3cf81e 100644 --- a/cookbooks/prometheus/templates/default/prometheus.yml.erb +++ b/cookbooks/prometheus/templates/default/prometheus.yml.erb @@ -6,7 +6,8 @@ global: alerting: alertmanagers: - - static_configs: + - path_prefix: /alertmanager + static_configs: - targets: - localhost:9093 @@ -17,10 +18,12 @@ scrape_configs: - job_name: prometheus scrape_interval: 5s scrape_timeout: 5s + metrics_path: /prometheus/metrics static_configs: - targets: - localhost:9090 - job_name: alertmanager + metrics_path: /alertmanager/metrics static_configs: - targets: - localhost:9093 -- 2.45.1