if exporter.is_a?(Hash)
name = exporter[:name]
address = exporter[:address]
+ metric_relabel = exporter[:metric_relabel] || []
else
name = key
address = exporter
+ metric_relabel = []
end
jobs[name] ||= []
- jobs[name] << { :address => address, :name => client.name }
+ jobs[name] << {
+ :address => address,
+ :instance => client.name.split(".").first,
+ :metric_relabel => metric_relabel
+ }
end
end
property :options, :kind_of => [String, Array]
property :environment, :kind_of => Hash, :default => {}
property :service, :kind_of => String
+property :metric_relabel, :kind_of => Array
action :create do
systemd_service service_name do
end
node.default[:prometheus][:exporters][new_resource.port] = {
- :name => new_resource.exporter, :address => listen_address
+ :name => new_resource.exporter,
+ :address => listen_address,
+ :metric_relabel => new_resource.metric_relabel
}
end
- targets:
- "<%= target[:address] %>"
labels:
- instance: <%= target[:name].split(".").first %>
+ instance: <%= target[:instance] %>
+<% end -%>
+<% end -%>
+ metric_relabel_configs:
+<% @jobs.sort.each do |name, targets| -%>
+<% targets.each do |target| -%>
+<% target[:metric_relabel].each do |relabel| -%>
+ - source_labels: [instance,<%= relabel[:source_labels] %>]
+ regex: "<%= target[:instance] %>;<%= relabel[:regex] %>"
+ action: <%= relabel[:action] %>
+<% end -%>
<% end -%>
<% end -%>