Commit 373c76a9 authored by Ahmad Sherif's avatar Ahmad Sherif
Browse files

Combine multiple probers into one

parent 02533e48
PATH
remote: .
specs:
gitlab-monitor (0.0.5)
gitlab-monitor (0.0.6)
pg (~> 0.18.4)
sinatra (~> 1.4.7)
......
......@@ -3,12 +3,14 @@ server:
listen_port: 4567
probes:
dead_tuples_count:
class_name: Database::DeadTuplesProber
methods:
- probe_db
opts:
connection_string: dbname=gitlabhq_development user=postgres
database:
multiple: true
dead_tuples_count:
class_name: Database::DeadTuplesProber
methods:
- probe_db
opts:
connection_string: dbname=gitlabhq_development user=postgres
git:
methods:
- probe_pull
......
......@@ -11,5 +11,6 @@ module GitLab
autoload :Database, "gitlab_monitor/database"
autoload :ProcessProber, "gitlab_monitor/process"
autoload :WebExporter, "gitlab_monitor/web_exporter"
autoload :Prober, "gitlab_monitor/prober"
end
end
module GitLab
module Monitor
# A class to combine multiple probers into one
class Prober
def initialize(prober_opts, metrics: PrometheusMetrics.new)
@prober_opts = prober_opts
@metrics = metrics
resolve_prober_classes
end
def probe_all
@prober_opts.each do |_probe_name, params|
Utils.wrap_in_array(params[:opts]).each do |opts|
prober = params[:class].new(opts, metrics: @metrics)
params[:methods].each do |meth|
prober.send(meth)
end
end
end
end
def write_to(target)
target.write(@metrics.to_s)
end
private
def resolve_prober_classes
@prober_opts.each do |probe_name, params|
prober_class_name = params[:class_name] || Utils.camel_case_string("#{probe_name}_prober")
klass = prober_class_name.split("::").reduce(GitLab::Monitor) { |a, e| a.const_get(e) }
params[:class] = klass
end
end
end
end
end
module GitLab
module Monitor
VERSION = "0.0.5".freeze
VERSION = "0.0.6".freeze
end
end
......@@ -17,30 +17,25 @@ module GitLab
set(:port, config.fetch(:listen_port, 4567))
end
def setup_probes(config) # rubocop:disable Metrics/AbcSize
def setup_probes(config)
(config || {}).each do |probe_name, params|
prober_class_name = params.delete(:class_name) || Utils.camel_case_string("#{probe_name}_prober")
prober_class = resolve_prober_class(prober_class_name)
opts =
if params.delete(:multiple)
params
else
{ probe_name => params }
end
get "/#{probe_name}" do
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 = Prober.new(opts, metrics: PrometheusMetrics.new(include_timestamp: false))
prober.probe_all
prober.write_to(response)
response
end
end
end
def resolve_prober_class(prober_class_name)
prober_class_name.split("::").reduce(GitLab::Monitor) do |ancestor, const_name|
ancestor.const_get(const_name)
end
end
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