Add action tag to more metrics

This commit is contained in:
Pawel Chojnacki 2017-09-06 03:19:39 +02:00
parent 6db3151fa1
commit aa25586afe
2 changed files with 30 additions and 7 deletions

View file

@ -9,14 +9,14 @@ module Gitlab
@metric_sql_duration_seconds ||= Gitlab::Metrics.histogram( @metric_sql_duration_seconds ||= Gitlab::Metrics.histogram(
:gitlab_sql_duration_seconds, :gitlab_sql_duration_seconds,
'SQL time', 'SQL time',
{}, { action: nil },
[0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0] [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0]
) )
end 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
self.class.metric_sql_duration_seconds.observe({ action: current_transaction.action }, event.duration / 1000.0)
current_transaction.increment(:sql_duration, event.duration, false) current_transaction.increment(:sql_duration, event.duration, false)
current_transaction.increment(:sql_count, 1, false) current_transaction.increment(:sql_count, 1, false)

View file

@ -87,7 +87,7 @@ module Gitlab
# event_name - The name of the event (e.g. "git_push"). # event_name - The name of the event (e.g. "git_push").
# tags - A set of tags to attach to the event. # tags - A set of tags to attach to the event.
def add_event(event_name, tags = {}) def add_event(event_name, tags = {})
Gitlab::Metrics.counter("gitlab_transaction_event_#{event_name}_total".to_sym, "Transaction event #{event_name}", tags).increment({}) self.class.metric_event_counter(event_name, tags).increment(tags.merge({ action: action }))
@metrics << Metric.new(EVENT_SERIES, { count: 1 }, tags, :event) @metrics << Metric.new(EVENT_SERIES, { count: 1 }, tags, :event)
end end
@ -101,14 +101,12 @@ module Gitlab
end end
def increment(name, value, compat = true) def increment(name, value, compat = true)
Gitlab::Metrics.counter("gitlab_transaction_#{name}_total".to_sym, "Transaction counter #{name}", {}) self.class.metric_transaction_counter(name).increment({ action: action }, value) if compat
.increment({}, value) if compat
@values[name] += value @values[name] += value
end end
def set(name, value, compat = true) def set(name, value, compat = true)
Gitlab::Metrics.gauge("gitlab_transaction_#{name}".to_sym, "Transaction gauge #{name}", {}, :livesum) self.class.metric_transaction_gauge(name).set({ action: action }, value) if compat
.set({}, value) if compat
@values[name] = value @values[name] = value
end end
@ -144,6 +142,31 @@ module Gitlab
Metrics.submit_metrics(submit_hashes) Metrics.submit_metrics(submit_hashes)
end end
private
def self.metric_event_counter(event_name, tags)
@metric_event_counters ||= {}
@metric_event_counters[event_name] ||= Gitlab::Metrics.counter(
"gitlab_transaction_event_#{event_name}_total".to_sym,
"Transaction event #{event_name} counter",
tags.merge({ action: nil })
)
end
def self.metric_transaction_counter(name)
@metric_transaction_counters ||= {}
@metric_transaction_counters[name] ||= Gitlab::Metrics.counter(
"gitlab_transaction_#{name}_total".to_sym, "Transaction #{name} counter", action: nil
)
end
def self.metric_transaction_gauge(name)
@metric_transaction_gauges ||= {}
@metric_transaction_gauges[name] ||= Gitlab::Metrics.gauge(
"gitlab_transaction_#{name}".to_sym, "Transaction gauge #{name}", { action: nil }, :livesum
)
end
end end
end end
end end