From: Tom Hughes Date: Wed, 20 Jul 2022 16:03:40 +0000 (+0100) Subject: Allow multiple modules to be monitored for a single SNMP target X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/6dda13cb4af5b26e536150c4d6885cf5550e98e7?ds=sidebyside Allow multiple modules to be monitored for a single SNMP target --- diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index fe359b450..36444527c 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -217,7 +217,7 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client snmp_targets << { :instance => instance, :target => details[:address], - :module => details[:module], + :modules => details[:modules], :address => client[:prometheus][:addresses]["snmp"], :labels => Array(details[:labels]) } diff --git a/cookbooks/prometheus/templates/default/prometheus.yml.erb b/cookbooks/prometheus/templates/default/prometheus.yml.erb index 9b24a4d45..bd4113524 100644 --- a/cookbooks/prometheus/templates/default/prometheus.yml.erb +++ b/cookbooks/prometheus/templates/default/prometheus.yml.erb @@ -85,10 +85,11 @@ scrape_configs: scrape_timeout: 2m metrics_path: /snmp static_configs: - - targets: <% @snmp_targets.sort_by { |t| t[:instance] }.each do |target| -%> - targets: - - "<%= target[:target] %>/<%= target[:module] %>/<%= target[:address] %>" +<% target[:modules].each do |module_name| -%> + - "<%= target[:target] %>/<%= module_name %>/<%= target[:address] %>" +<% end -%> labels: instance: <%= target[:instance] %> <% target[:labels].sort.each do |name, value| -%> diff --git a/roles/fafnir.rb b/roles/fafnir.rb index cbd12fc1c..a6494a660 100644 --- a/roles/fafnir.rb +++ b/roles/fafnir.rb @@ -39,9 +39,9 @@ default_attributes( }, :prometheus => { :snmp => { - "pdu1" => { :address => "10.0.64.100", :module => "apcups", :labels => { "site" => "dublin" } }, - "pdu2" => { :address => "10.0.64.101", :module => "apcups", :labels => { "site" => "dublin" } }, - "switch1" => { :address => "184.104.226.97", :module => "if_mib", :labels => { "site" => "dublin" } } + "pdu1" => { :address => "10.0.64.100", :modules => ["apcups"], :labels => { "site" => "dublin" } }, + "pdu2" => { :address => "10.0.64.101", :modules => ["apcups"], :labels => { "site" => "dublin" } }, + "switch1" => { :address => "184.104.226.97", :modules => ["if_mib"], :labels => { "site" => "dublin" } } }, :metrics => { :uplink_interface => { diff --git a/roles/ironbelly.rb b/roles/ironbelly.rb index 866664e38..cc09fd0d0 100644 --- a/roles/ironbelly.rb +++ b/roles/ironbelly.rb @@ -60,9 +60,9 @@ default_attributes( }, :prometheus => { :snmp => { - "pdu1" => { :address => "10.0.48.100", :module => "apcups", :labels => { "site" => "amsterdam" } }, - "pdu2" => { :address => "10.0.48.101", :module => "apcups", :labels => { "site" => "amsterdam" } }, - "switch1" => { :address => "130.117.76.2", :module => "if_mib", :labels => { "site" => "amsterdam" } } + "pdu1" => { :address => "10.0.48.100", :modules => ["apcups"], :labels => { "site" => "amsterdam" } }, + "pdu2" => { :address => "10.0.48.101", :modules => ["apcups"], :labels => { "site" => "amsterdam" } }, + "switch1" => { :address => "130.117.76.2", :modules => ["if_mib"], :labels => { "site" => "amsterdam" } } }, :metrics => { :uplink_interface => {