remove common Base Sampler code

This commit is contained in:
Pawel Chojnacki 2017-09-04 22:14:54 +02:00
parent f464adaaf6
commit b6d75b2955
2 changed files with 18 additions and 55 deletions

View file

@ -14,8 +14,6 @@ the settings page with a default template. To configure the template, see the
## Requirements
[supported performance metrics](https://docs.gitlab.com/ee/user/project/integrations/prometheus_library/metrics.html)
Integration with Prometheus requires the following:
1. GitLab 9.0 or higher

View file

@ -2,20 +2,7 @@ require 'logger'
module Gitlab
module Metrics
module Samplers
class BaseSampler
def self.initialize_instance(*args)
raise "#{name} singleton instance already initialized" if @instance
@instance = new(*args)
at_exit(&@instance.method(:stop))
@instance
end
def self.instance
@instance
end
attr_reader :running
class BaseSampler < Daemon
# interval - The sampling interval in seconds.
def initialize(interval)
interval_half = interval.to_f / 2
@ -23,44 +10,7 @@ module Gitlab
@interval = interval
@interval_steps = (-interval_half..interval_half).step(0.1).to_a
@mutex = Mutex.new
end
def enabled?
true
end
def start
return unless enabled?
@mutex.synchronize do
return if running
@running = true
@thread = Thread.new do
sleep(sleep_interval)
while running
safe_sample
sleep(sleep_interval)
end
end
end
end
def stop
@mutex.synchronize do
return unless running
@running = false
if @thread
@thread.wakeup if @thread.alive?
@thread.join
@thread = nil
end
end
super()
end
def safe_sample
@ -90,7 +40,22 @@ module Gitlab
end
end
end
private
def start_working
@running = true
sleep(sleep_interval)
while running
safe_sample
end
end
def stop_working
@running = false
end
end
end
end
end
end