diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-08-11 22:00:06 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-02 18:09:21 +0100 |
commit | 0bfe79019d1743407c7df59d1f44cc470dd48e4b (patch) | |
tree | 1d6fb7e5094ebb0930f88a0200e9f6acea2a3a7d | |
parent | 03b38a4a8dd5ba01043264df31b7f5faf6217e1b (diff) | |
download | gitlab-ce-0bfe79019d1743407c7df59d1f44cc470dd48e4b.tar.gz |
Add samples total and cleanup
-rw-r--r-- | doc/user/project/integrations/prometheus.md | 2 | ||||
-rw-r--r-- | lib/gitlab/metrics/samplers/ruby_sampler.rb | 79 |
2 files changed, 55 insertions, 26 deletions
diff --git a/doc/user/project/integrations/prometheus.md b/doc/user/project/integrations/prometheus.md index 5fefb3b69c4..e046b494724 100644 --- a/doc/user/project/integrations/prometheus.md +++ b/doc/user/project/integrations/prometheus.md @@ -14,6 +14,8 @@ 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 diff --git a/lib/gitlab/metrics/samplers/ruby_sampler.rb b/lib/gitlab/metrics/samplers/ruby_sampler.rb index 455085731a8..fc7870eb3f8 100644 --- a/lib/gitlab/metrics/samplers/ruby_sampler.rb +++ b/lib/gitlab/metrics/samplers/ruby_sampler.rb @@ -2,15 +2,14 @@ module Gitlab module Metrics module Samplers class RubySampler < BaseSampler - COUNTS = [:count, :minor_gc_count, :major_gc_count] def metrics @metrics ||= init_metrics end - def with_prefix(name) - "ruby_gc_#{name}".to_sym + def with_prefix(prefix, name) + "ruby_#{prefix}_#{name}".to_sym end def to_doc_string(name) @@ -23,22 +22,40 @@ module Gitlab def initialize(interval) super(interval) - GC::Profiler.enable - Rails.logger.info("123") - init_metrics + if Gitlab::Metrics.mri? + require 'allocations' + + Allocations.start + end end def init_metrics metrics = {} - metrics[:total_time] = Gitlab::Metrics.gauge(with_prefix(:total_time), to_doc_string(:total_time), labels, :livesum) + metrics[:samples_total] = Gitlab::Metrics.counter(with_prefix(:sampler, :total), 'Total count of samples') + metrics[:total_time] = Gitlab::Metrics.gauge(with_prefix(:gc, :time_total), 'Total GC time', labels, :livesum) GC.stat.keys.each do |key| - metrics[key] = Gitlab::Metrics.gauge(with_prefix(key), to_doc_string(key), labels, :livesum) + metrics[key] = Gitlab::Metrics.gauge(with_prefix(:gc, key), to_doc_string(key), labels, :livesum) end + + metrics[:objects_total] = Gitlab::Metrics.gauge(with_prefix(:objects, :total), 'Objects total', labels.merge(class: nil), :livesum) + metrics end def sample + + metrics[:samples_total].increment(labels) + sample_gc + sample_objects + rescue => ex + puts ex + + end + + private + + def sample_gc metrics[:total_time].set(labels, GC::Profiler.total_time * 1000) GC.stat.each do |key, value| @@ -46,6 +63,34 @@ module Gitlab end end + def sample_objects + ss_objects.each do |name, count| + metrics[:objects_total].set(labels.merge(class: name), count) + end + end + + if Metrics.mri? + def ss_objects + sample = Allocations.to_hash + counts = sample.each_with_object({}) do |(klass, count), hash| + name = klass.name + + next unless name + + hash[name] = count + end + + # Symbols aren't allocated so we'll need to add those manually. + counts['Symbol'] = Symbol.all_symbols.length + counts + end + else + def ss_objects + + end + end + + def source_label if Sidekiq.server? { source: 'sidekiq' } @@ -65,24 +110,6 @@ module Gitlab { unicorn: 'master' } end end - - def sample_gc - time = GC::Profiler.total_time * 1000.0 - stats = GC.stat.merge(total_time: time) - - # We want the difference of GC runs compared to the last sample, not the - # total amount since the process started. - - stats[:minor_gc_count] = - @last_minor_gc.compared_with(stats[:minor_gc_count]) - - stats[:major_gc_count] = - @last_major_gc.compared_with(stats[:major_gc_count]) - - stats[:count] = stats[:minor_gc_count] + stats[:major_gc_count] - - add_metric('gc_statistics', stats) - end end end end |