Commit c97dc61a authored by Pawel Chojnacki's avatar Pawel Chojnacki

Cleanup transaction metrics

parent 3cc28601
...@@ -535,6 +535,7 @@ Settings.webpack.dev_server['port'] ||= 3808 ...@@ -535,6 +535,7 @@ Settings.webpack.dev_server['port'] ||= 3808
Settings['monitoring'] ||= Settingslogic.new({}) Settings['monitoring'] ||= Settingslogic.new({})
Settings.monitoring['ip_whitelist'] ||= ['127.0.0.1/8'] Settings.monitoring['ip_whitelist'] ||= ['127.0.0.1/8']
Settings.monitoring['unicorn_sampler_interval'] ||= 10 Settings.monitoring['unicorn_sampler_interval'] ||= 10
Settings.monitoring['ruby_sampler_interval'] ||= 60
Settings.monitoring['sidekiq_exporter'] ||= Settingslogic.new({}) Settings.monitoring['sidekiq_exporter'] ||= Settingslogic.new({})
Settings.monitoring.sidekiq_exporter['enabled'] ||= false Settings.monitoring.sidekiq_exporter['enabled'] ||= false
Settings.monitoring.sidekiq_exporter['address'] ||= 'localhost' Settings.monitoring.sidekiq_exporter['address'] ||= 'localhost'
......
...@@ -11,7 +11,15 @@ Prometheus::Client.configure do |config| ...@@ -11,7 +11,15 @@ Prometheus::Client.configure do |config|
config.multiprocess_files_dir ||= Rails.root.join('tmp/prometheus_multiproc_dir') config.multiprocess_files_dir ||= Rails.root.join('tmp/prometheus_multiproc_dir')
end end
config.pid_provider = Prometheus::Client::Support::Unicorn.method(:worker_pid_provider) config.pid_provider = -> do
wid = Prometheus::Client::Support::Unicorn.worker_id
wid = Process.pid if wid.nil?
if wid.nil?
"process_pid_#{Process.pid}"
else
"worker_id_#{wid}"
end
end
end end
Sidekiq.configure_server do |config| Sidekiq.configure_server do |config|
...@@ -20,6 +28,7 @@ Sidekiq.configure_server do |config| ...@@ -20,6 +28,7 @@ Sidekiq.configure_server do |config|
end end
end end
# if Gitlab::Metrics.prometheus_metrics_enabled? if Gitlab::Metrics.prometheus_metrics_enabled?
Gitlab::Metrics::Samplers::RubySampler.initialize_instance(60.second).start Gitlab::Metrics::Samplers::UnicornSampler.initialize_instance(Settings.monitoring.unicorn_sampler_interval).start
# end Gitlab::Metrics::Samplers::RubySampler.initialize_instance(Settings.monitoring.ruby_sampler_interval).start
end
...@@ -123,10 +123,6 @@ def instrument_classes(instrumentation) ...@@ -123,10 +123,6 @@ def instrument_classes(instrumentation)
end end
# rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/AbcSize
unless Sidekiq.server?
Gitlab::Metrics::Samplers::UnicornSampler.initialize_instance(Settings.monitoring.unicorn_sampler_interval).start
end
Gitlab::Application.configure do |config| Gitlab::Application.configure do |config|
# 0 should be Sentry to catch errors in this middleware # 0 should be Sentry to catch errors in this middleware
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware) config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
......
...@@ -102,9 +102,12 @@ module Gitlab ...@@ -102,9 +102,12 @@ module Gitlab
real_time = (real_stop - real_start) * 1000.0 real_time = (real_stop - real_start) * 1000.0
cpu_time = cpu_stop - cpu_start cpu_time = cpu_stop - cpu_start
trans.increment("#{name}_real_time", real_time) Gitlab::Metrics.histogram("gitlab_#{name}_real_duration".to_sym, "Measure #{name}", {}, [1, 2, 5, 10, 20, 50, 100, 1000]).observe({}, real_time)
trans.increment("#{name}_cpu_time", cpu_time) Gitlab::Metrics.histogram("gitlab_#{name}_cpu_duration".to_sym, "Measure #{name}", {}, [1, 2, 5, 10, 20, 50, 100, 1000]).observe({}, cpu_time)
trans.increment("#{name}_call_count", 1)
trans.increment("#{name}_real_time", real_time, false)
trans.increment("#{name}_cpu_time", cpu_time, false)
trans.increment("#{name}_call_count", 1, false)
retval retval
end end
......
...@@ -5,11 +5,21 @@ module Gitlab ...@@ -5,11 +5,21 @@ module Gitlab
class ActiveRecord < ActiveSupport::Subscriber class ActiveRecord < ActiveSupport::Subscriber
attach_to :active_record attach_to :active_record
def self.metric_sql_duration_seconds
@metric_sql_duration_seconds ||= Gitlab::Metrics.histogram(
:gitlab_sql_duration_seconds,
'SQL duration seconds',
{},
[0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0]
)
end
def sql(event) def sql(event)
self.class.metric_sql_duration_secodnds.observe({}, event.duration/1000.0)
return unless current_transaction return unless current_transaction
current_transaction.increment(:sql_duration, event.duration) current_transaction.increment(:sql_duration, event.duration, false)
current_transaction.increment(:sql_count, 1) current_transaction.increment(:sql_count, 1, false)
end end
private private
......
...@@ -40,21 +40,21 @@ module Gitlab ...@@ -40,21 +40,21 @@ module Gitlab
@memory_after - @memory_before @memory_after - @memory_before
end end
def self.metric_transaction_duration_milliseconds def self.metric_transaction_duration_seconds
@metrics_transaction_duration_milliseconds ||= Gitlab::Metrics.histogram( @metric_transaction_duration_seconds ||= Gitlab::Metrics.histogram(
:gitlab_transaction_duration_milliseconds, :gitlab_transaction_duration_seconds,
'Transaction duration milliseconds', 'Transaction duration seconds',
{}, {},
[1, 2, 5, 10, 20, 50, 100, 500, 10000] [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0]
) )
end end
def self.metric_transaction_allocated_memory_megabytes def self.metric_transaction_allocated_memory_bytes
@metric_transaction_allocated_memory_megabytes ||= Gitlab::Metrics.histogram( @metric_transaction_allocated_memory_bytes ||= Gitlab::Metrics.histogram(
:gitlab_transaction_allocated_memory_megabytes, :gitlab_transaction_allocated_memory_bytes,
'Transaction allocated memory bytes', 'Transaction allocated memory bytes',
{}, {},
[1, 2, 5, 10, 20, 100] [500000, 1000000, 2000000, 5000000, 10000000, 20000000, 100000000]
) )
end end
...@@ -69,8 +69,8 @@ module Gitlab ...@@ -69,8 +69,8 @@ module Gitlab
@memory_after = System.memory_usage @memory_after = System.memory_usage
@finished_at = System.monotonic_time @finished_at = System.monotonic_time
Transaction.metric_transaction_duration_milliseconds.observe({}, duration) Transaction.metric_transaction_duration_seconds.observe({}, duration * 1000)
Transaction.metric_transaction_allocated_memory_megabytes.observe({}, allocated_memory) Transaction.metric_transaction_allocated_memory_bytes.observe({}, allocated_memory / 2 ^ 20)
Thread.current[THREAD_KEY] = nil Thread.current[THREAD_KEY] = nil
end end
...@@ -100,13 +100,15 @@ module Gitlab ...@@ -100,13 +100,15 @@ module Gitlab
method method
end end
def increment(name, value) def increment(name, value, compat = true)
Gitlab::Metrics.counter("gitlab_transaction_#{name}_total".to_sym, "Transaction counter #{name}", {}).increment({}, value) Gitlab::Metrics.counter("gitlab_transaction_#{name}_total".to_sym, "Transaction counter #{name}", {})
.increment({}, value) if compat
@values[name] += value @values[name] += value
end end
def set(name, value) def set(name, value, compat = true)
Gitlab::Metrics.gauge("gitlab_transaction_#{name}".to_sym, "Transaction gauge #{name}", {}, :livesum).set({}, value) Gitlab::Metrics.gauge("gitlab_transaction_#{name}".to_sym, "Transaction gauge #{name}", {}, :livesum)
.set({}, value) if compat
@values[name] = value @values[name] = value
end 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