1f9edb7c4a
Previously, both InfluxSampler and RubySampler were relying on the `GC::Profiler.total_time` data which is the sum over the list of captured GC events. Also, both samplers asynchronously called `GC::Profiler.clear` which led to incorrect metric data because each sampler has the wrong assumption it is the only object who calls `GC::Profiler.clear` and thus could rely on the gathered results between such calls. We should ensure that `GC::Profiler.total_time` is called only in one place making it possible to rely on accumulated data between such wipes. Also, we need to track the amount of profiler reports we lost.
53 lines
1.3 KiB
Ruby
53 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module Metrics
|
|
module Samplers
|
|
# Class that sends certain metrics to InfluxDB at a specific interval.
|
|
#
|
|
# This class is used to gather statistics that can't be directly associated
|
|
# with a transaction such as system memory usage, garbage collection
|
|
# statistics, etc.
|
|
class InfluxSampler < BaseSampler
|
|
# interval - The sampling interval in seconds.
|
|
def initialize(interval = ::Gitlab::Metrics.settings[:sample_interval])
|
|
super(interval)
|
|
@last_step = nil
|
|
|
|
@metrics = []
|
|
end
|
|
|
|
def sample
|
|
sample_memory_usage
|
|
sample_file_descriptors
|
|
|
|
flush
|
|
ensure
|
|
@metrics.clear
|
|
end
|
|
|
|
def flush
|
|
::Gitlab::Metrics.submit_metrics(@metrics.map(&:to_hash))
|
|
end
|
|
|
|
def sample_memory_usage
|
|
add_metric('memory_usage', value: System.memory_usage)
|
|
end
|
|
|
|
def sample_file_descriptors
|
|
add_metric('file_descriptors', value: System.file_descriptor_count)
|
|
end
|
|
|
|
def add_metric(series, values, tags = {})
|
|
prefix = sidekiq? ? 'sidekiq_' : 'rails_'
|
|
|
|
@metrics << Metric.new("#{prefix}#{series}", values, tags)
|
|
end
|
|
|
|
def sidekiq?
|
|
Sidekiq.server?
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|