BigW Consortium Gitlab

Commit c97dc61a by Pawel Chojnacki

Cleanup transaction metrics

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