Commit b6d75b29 authored by Pawel Chojnacki's avatar Pawel Chojnacki

remove common Base Sampler code

parent f464adaa
......@@ -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
......
......@@ -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
\ No newline at end of file
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