Commit 382c7682 authored by Ahmad Sherif's avatar Ahmad Sherif
Browse files

Allow specifying multiple configurations for a single prober

parent 6c21635a
......@@ -56,6 +56,17 @@ module GitLab
File.read("/proc/uptime").split(" ")[0].to_f
end
module_function :system_uptime
def wrap_in_array(object)
if object.nil?
[]
elsif object.respond_to?(:to_ary)
object.to_ary || [object]
else
[object]
end
end
module_function :wrap_in_array
end
end
end
......@@ -5,17 +5,21 @@ module GitLab
# Metrics web exporter
class WebExporter < Sinatra::Base
class << self
def setup(config)
def setup(config) # rubocop:disable Metrics/AbcSize
config[:probes].each do |probe_name, params|
prober_class_name = params.delete(:class_name) || Utils.camel_case_string("#{probe_name}_prober")
prober_class = GitLab::Monitor.const_get(prober_class_name)
get "/#{probe_name}" do
prober = prober_class.new(params[:opts], metrics: PrometheusMetrics.new(include_timestamp: false))
params[:methods].each do |meth|
prober.send(meth)
Utils.wrap_in_array(params[:opts]).each do |opts|
prober = prober_class.new(opts, metrics: PrometheusMetrics.new(include_timestamp: false))
params[:methods].each do |meth|
prober.send(meth)
end
prober.write_to(response)
end
prober.write_to(response)
response
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment