Improve StatsD instrumentation
This commit is contained in:
parent
7329fbd8a4
commit
d567f21d4f
4 changed files with 24 additions and 27 deletions
|
@ -3,18 +3,11 @@
|
|||
StatsD.prefix = 'mastodon'
|
||||
StatsD.default_sample_rate = 1
|
||||
|
||||
StatsDMonitor.extend(StatsD::Instrument)
|
||||
StatsDMonitor.statsd_measure(:call, 'request.duration')
|
||||
ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload|
|
||||
action = payload[:action] || :increment
|
||||
measurement = payload[:measurement]
|
||||
value = payload[:value]
|
||||
key_name = "#{name}.#{measurement}"
|
||||
|
||||
STATSD_REQUEST_METRICS = {
|
||||
'request.status.success' => 200,
|
||||
'request.status.not_found' => 404,
|
||||
'request.status.too_many_requests' => 429,
|
||||
'request.status.internal_server_error' => 500,
|
||||
}.freeze
|
||||
|
||||
STATSD_REQUEST_METRICS.each do |name, code|
|
||||
StatsDMonitor.statsd_count_if(:call, name) do |status, _env, _body|
|
||||
status.to_i == code
|
||||
end
|
||||
StatsD.send(action.to_s, key_name, (value || 1))
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue