X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/e35dfb67e1c89fd5badd5229336a5371ab2f8a52..bb01eaa9176f18aacc218e8f706f987afd13595e:/cookbooks/prometheus/recipes/server.rb diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index 414819160..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| @@ -136,6 +143,7 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client name = exporter[:name] address = exporter[:address] sni = exporter[:sni] + labels = Array(exporter[:labels]) scrape_interval = exporter[:scrape_interval] scrape_timeout = exporter[:scrape_timeout] metric_relabel = exporter[:metric_relabel] || [] @@ -143,6 +151,7 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client name = key address = exporter sni = nil + labels = [] scrape_interval = nil scrape_timeout = nil metric_relabel = [] @@ -153,12 +162,22 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client :address => address, :sni => sni, :instance => client.name.split(".").first, + :labels => labels, :scrape_interval => scrape_interval, :scrape_timeout => scrape_timeout, :metric_relabel => metric_relabel } 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, @@ -196,6 +215,8 @@ prometheus_exporter "ssl" do register_target false end +package "prometheus" + systemd_service "prometheus-executable" do service "prometheus" dropin "executable" @@ -209,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 @@ -223,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 @@ -258,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 @@ -288,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 @@ -296,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