X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/88f820a038a839a687db7374235eca3003790296..5fde77fb90280da2c008bb5e8e83f6635b999715:/cookbooks/prometheus/recipes/server.rb diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index 07a96b912..45550368c 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -46,7 +46,7 @@ end cache_dir = Chef::Config[:file_cache_path] -prometheus_version = "2.44.0" +prometheus_version = "2.45.0" alertmanager_version = "0.25.0" karma_version = "0.114" @@ -56,57 +56,63 @@ directory "/opt/prometheus-server" do mode "755" end -remote_file "#{cache_dir}/prometheus.linux-amd64.tar.gz" do - source "https://github.com/prometheus/prometheus/releases/download/v#{prometheus_version}/prometheus-#{prometheus_version}.linux-amd64.tar.gz" +prometheus_arch = if arm? + "arm64" + else + "amd64" + end + +remote_file "#{cache_dir}/prometheus.linux.tar.gz" do + source "https://github.com/prometheus/prometheus/releases/download/v#{prometheus_version}/prometheus-#{prometheus_version}.linux-#{prometheus_arch}.tar.gz" owner "root" group "root" mode "644" backup false end -archive_file "#{cache_dir}/prometheus.linux-amd64.tar.gz" do +archive_file "#{cache_dir}/prometheus.linux.tar.gz" do action :nothing destination "/opt/prometheus-server/prometheus" overwrite true strip_components 1 owner "root" group "root" - subscribes :extract, "remote_file[#{cache_dir}/prometheus.linux-amd64.tar.gz]", :immediately + subscribes :extract, "remote_file[#{cache_dir}/prometheus.linux.tar.gz]", :immediately end -remote_file "#{cache_dir}/alertmanager.linux-amd64.tar.gz" do - source "https://github.com/prometheus/alertmanager/releases/download/v#{alertmanager_version}/alertmanager-#{alertmanager_version}.linux-amd64.tar.gz" +remote_file "#{cache_dir}/alertmanager.linux.tar.gz" do + source "https://github.com/prometheus/alertmanager/releases/download/v#{alertmanager_version}/alertmanager-#{alertmanager_version}.linux-#{prometheus_arch}.tar.gz" owner "root" group "root" mode "644" backup false end -archive_file "#{cache_dir}/alertmanager.linux-amd64.tar.gz" do +archive_file "#{cache_dir}/alertmanager.linux.tar.gz" do action :nothing destination "/opt/prometheus-server/alertmanager" overwrite true strip_components 1 owner "root" group "root" - subscribes :extract, "remote_file[#{cache_dir}/alertmanager.linux-amd64.tar.gz]", :immediately + subscribes :extract, "remote_file[#{cache_dir}/alertmanager.linux.tar.gz]", :immediately end -remote_file "#{cache_dir}/karma-linux-amd64.tar.gz" do - source "https://github.com/prymitive/karma/releases/download/v#{karma_version}/karma-linux-amd64.tar.gz" +remote_file "#{cache_dir}/karma-linux.tar.gz" do + source "https://github.com/prymitive/karma/releases/download/v#{karma_version}/karma-linux-#{prometheus_arch}.tar.gz" owner "root" group "root" mode "644" backup false end -archive_file "#{cache_dir}/karma-linux-amd64.tar.gz" do +archive_file "#{cache_dir}/karma-linux.tar.gz" do action :nothing destination "/opt/prometheus-server/karma" overwrite true owner "root" group "root" - subscribes :extract, "remote_file[#{cache_dir}/karma-linux-amd64.tar.gz]", :immediately + subscribes :extract, "remote_file[#{cache_dir}/karma-linux.tar.gz]", :immediately end search(:node, "roles:gateway") do |gateway| @@ -120,6 +126,7 @@ search(:node, "roles:gateway") do |gateway| end jobs = {} +junos_targets = [] snmp_targets = [] search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client| @@ -162,6 +169,15 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client } end + Hash(client[:prometheus][:junos]).each do |instance, details| + junos_targets << { + :instance => instance, + :target => details[:address], + :address => client[:prometheus][:addresses]["junos"], + :labels => Array(details[:labels]) + } + end + Hash(client[:prometheus][:snmp]).each do |instance, details| snmp_targets << { :instance => instance, @@ -214,7 +230,7 @@ template "/etc/prometheus/prometheus.yml" do owner "root" group "root" mode "644" - variables :jobs => jobs, :snmp_targets => snmp_targets, :certificates => certificates + variables :jobs => jobs, :junos_targets => junos_targets, :snmp_targets => snmp_targets, :certificates => certificates end template "/etc/prometheus/alert_rules.yml" do @@ -228,7 +244,7 @@ service "prometheus" do action [:enable, :start] subscribes :reload, "template[/etc/prometheus/prometheus.yml]" subscribes :reload, "template[/etc/prometheus/alert_rules.yml]" - subscribes :restart, "archive_file[#{cache_dir}/prometheus.linux-amd64.tar.gz]" + subscribes :restart, "archive_file[#{cache_dir}/prometheus.linux.tar.gz]" end systemd_service "prometheus-alertmanager" do @@ -263,7 +279,7 @@ service "prometheus-alertmanager" do action [:enable, :start] subscribes :reload, "template[/etc/prometheus/alertmanager.yml]" subscribes :restart, "systemd_service[prometheus-alertmanager]" - subscribes :restart, "archive_file[#{cache_dir}/alertmanager.linux-amd64.tar.gz]" + subscribes :restart, "archive_file[#{cache_dir}/alertmanager.linux.tar.gz]" end directory "/etc/amtool" do @@ -293,7 +309,7 @@ end systemd_service "prometheus-karma" do description "Alert dashboard for Prometheus Alertmanager" user "prometheus" - exec_start "/opt/prometheus-server/karma/karma-linux-amd64 --config.file=/etc/prometheus/karma.yml" + exec_start "/opt/prometheus-server/karma/karma-linux-#{prometheus_arch} --config.file=/etc/prometheus/karma.yml" sandbox :enable_network => true restart "on-failure" end @@ -301,7 +317,7 @@ end service "prometheus-karma" do action [:enable, :start] subscribes :restart, "template[/etc/prometheus/karma.yml]" - subscribes :restart, "archive_file[#{cache_dir}/karma-linux-amd64.tar.gz]" + subscribes :restart, "archive_file[#{cache_dir}/karma-linux.tar.gz]" subscribes :restart, "systemd_service[prometheus-karma]" end