+default[:prometheus][:addresses] = {}
default[:prometheus][:exporters] = {}
+default[:prometheus][:snmp] = {}
if node[:recipes].include?("prometheus::server")
default[:apt][:sources] |= ["grafana"]
]
metric_relabel metric_relabel
end
+
+unless node[:prometheus][:snmp].empty?
+ prometheus_exporter "snmp" do
+ port 9116
+ options "--config.file=/opt/prometheus/exporters/snmp/snmp.yml"
+ register_target false
+ end
+end
end
jobs = {}
+snmp_targets = []
search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client|
if client[:prometheus][:mode] == "wireguard"
:metric_relabel => metric_relabel
}
end
+
+ Hash(client[:prometheus][:snmp]).each do |instance, details|
+ snmp_targets << {
+ :instance => instance,
+ :target => details[:address],
+ :module => details[:module],
+ :address => client[:prometheus][:addresses]["snmp"]
+ }
+ end
end
certificates = search(:node, "letsencrypt:certificates").each_with_object({}) do |n, c|
owner "root"
group "root"
mode "644"
- variables :jobs => jobs, :certificates => certificates
+ variables :jobs => jobs, :snmp_targets => snmp_targets, :certificates => certificates
end
template "/etc/prometheus/alert_rules.yml" do
only_if { node[:prometheus][:mode] == "external" }
end
+ node.default[:prometheus][:addresses][new_resource.exporter] = listen_address
+
if new_resource.register_target
node.default[:prometheus][:exporters][new_resource.port] = {
:name => new_resource.exporter,
<% end -%>
<% end -%>
<% end -%>
+ - job_name: snmp
+ scrape_interval: 5m
+ scrape_timeout: 1m
+ metrics_path: /snmp
+ static_configs:
+ - targets:
+<% @snmp_targets.sort_by { |t| t[:instance] }.each do |target| -%>
+ - targets:
+ - "<%= target[:target] %>/<%= target[:module] %>/<%= target[:address] %>"
+ labels:
+ instance: <%= target[:instance] %>
+<% end -%>
+ relabel_configs:
+ - source_labels: [__address__]
+ regex: "([^/]+)/[^/]+/.*"
+ target_label: __param_target
+ - source_labels: [__address__]
+ regex: "[^/]+/([^/]+)/.*"
+ target_label: __param_module
+ - source_labels: [__address__]
+ regex: "[^/]+/[^/]+/(.*)"
+ target_label: __address__
remote_write:
- url: "http://localhost:9201/write"
:planet => {
:replication => "enabled"
},
+ :prometheus => {
+ :snmp => {
+ "pdu1" => { :address => "10.0.48.100", :module => "apcups" },
+ "pdu2" => { :address => "10.0.48.101", :module => "apcups" },
+ "switch1" => { :address => "130.117.76.2", :module => "if_mib" }
+ }
+ },
:rsyncd => {
:modules => {
:hosts => {