Use separate series for Rails/Sidekiq sample stats
This removes the need for any tags to differentiate between Sidekiq and Rails statistics while still being able to separate the two.
This commit is contained in:
parent
825b46f8a3
commit
2ea464bb27
2 changed files with 44 additions and 13 deletions
|
@ -50,12 +50,11 @@ module Gitlab
|
|||
end
|
||||
|
||||
def sample_memory_usage
|
||||
@metrics << Metric.new('memory_usage', value: System.memory_usage)
|
||||
add_metric('memory_usage', value: System.memory_usage)
|
||||
end
|
||||
|
||||
def sample_file_descriptors
|
||||
@metrics << Metric.
|
||||
new('file_descriptors', value: System.file_descriptor_count)
|
||||
add_metric('file_descriptors', value: System.file_descriptor_count)
|
||||
end
|
||||
|
||||
if Metrics.mri?
|
||||
|
@ -69,7 +68,7 @@ module Gitlab
|
|||
counts['Symbol'] = Symbol.all_symbols.length
|
||||
|
||||
counts.each do |name, count|
|
||||
@metrics << Metric.new('object_counts', { count: count }, type: name)
|
||||
add_metric('object_counts', { count: count }, type: name)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@ -91,7 +90,17 @@ module Gitlab
|
|||
|
||||
stats[:count] = stats[:minor_gc_count] + stats[:major_gc_count]
|
||||
|
||||
@metrics << Metric.new('gc_statistics', stats)
|
||||
add_metric('gc_statistics', stats)
|
||||
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
|
||||
|
|
|
@ -51,8 +51,8 @@ describe Gitlab::Metrics::Sampler do
|
|||
expect(Gitlab::Metrics::System).to receive(:memory_usage).
|
||||
and_return(9000)
|
||||
|
||||
expect(Gitlab::Metrics::Metric).to receive(:new).
|
||||
with('memory_usage', value: 9000).
|
||||
expect(sampler).to receive(:add_metric).
|
||||
with(/memory_usage/, value: 9000).
|
||||
and_call_original
|
||||
|
||||
sampler.sample_memory_usage
|
||||
|
@ -64,8 +64,8 @@ describe Gitlab::Metrics::Sampler do
|
|||
expect(Gitlab::Metrics::System).to receive(:file_descriptor_count).
|
||||
and_return(4)
|
||||
|
||||
expect(Gitlab::Metrics::Metric).to receive(:new).
|
||||
with('file_descriptors', value: 4).
|
||||
expect(sampler).to receive(:add_metric).
|
||||
with(/file_descriptors/, value: 4).
|
||||
and_call_original
|
||||
|
||||
sampler.sample_file_descriptors
|
||||
|
@ -74,8 +74,8 @@ describe Gitlab::Metrics::Sampler do
|
|||
|
||||
describe '#sample_objects' do
|
||||
it 'adds a metric containing the amount of allocated objects' do
|
||||
expect(Gitlab::Metrics::Metric).to receive(:new).
|
||||
with('object_counts', an_instance_of(Hash), an_instance_of(Hash)).
|
||||
expect(sampler).to receive(:add_metric).
|
||||
with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)).
|
||||
at_least(:once).
|
||||
and_call_original
|
||||
|
||||
|
@ -87,11 +87,33 @@ describe Gitlab::Metrics::Sampler do
|
|||
it 'adds a metric containing garbage collection statistics' do
|
||||
expect(GC::Profiler).to receive(:total_time).and_return(0.24)
|
||||
|
||||
expect(Gitlab::Metrics::Metric).to receive(:new).
|
||||
with('gc_statistics', an_instance_of(Hash)).
|
||||
expect(sampler).to receive(:add_metric).
|
||||
with(/gc_statistics/, an_instance_of(Hash)).
|
||||
and_call_original
|
||||
|
||||
sampler.sample_gc
|
||||
end
|
||||
end
|
||||
|
||||
describe '#add_metric' do
|
||||
it 'prefixes the series name for a Rails process' do
|
||||
expect(sampler).to receive(:sidekiq?).and_return(false)
|
||||
|
||||
expect(Gitlab::Metrics::Metric).to receive(:new).
|
||||
with('rails_cats', { value: 10 }, {}).
|
||||
and_call_original
|
||||
|
||||
sampler.add_metric('cats', value: 10)
|
||||
end
|
||||
|
||||
it 'prefixes the series name for a Sidekiq process' do
|
||||
expect(sampler).to receive(:sidekiq?).and_return(true)
|
||||
|
||||
expect(Gitlab::Metrics::Metric).to receive(:new).
|
||||
with('sidekiq_cats', { value: 10 }, {}).
|
||||
and_call_original
|
||||
|
||||
sampler.add_metric('cats', value: 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue