mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-24 18:13:42 +01:00
Add optional StatsD performance tracking
This commit is contained in:
parent
7cfd5b680a
commit
306eb6e9c9
7 changed files with 43 additions and 4 deletions
1
Gemfile
1
Gemfile
|
@ -47,6 +47,7 @@ gem 'sidekiq'
|
||||||
gem 'rails-settings-cached'
|
gem 'rails-settings-cached'
|
||||||
gem 'pg_search'
|
gem 'pg_search'
|
||||||
gem 'simple-navigation'
|
gem 'simple-navigation'
|
||||||
|
gem 'statsd-instrument'
|
||||||
|
|
||||||
gem 'react-rails'
|
gem 'react-rails'
|
||||||
gem 'browserify-rails'
|
gem 'browserify-rails'
|
||||||
|
|
|
@ -370,6 +370,7 @@ GEM
|
||||||
actionpack (>= 4.0)
|
actionpack (>= 4.0)
|
||||||
activesupport (>= 4.0)
|
activesupport (>= 4.0)
|
||||||
sprockets (>= 3.0.0)
|
sprockets (>= 3.0.0)
|
||||||
|
statsd-instrument (2.1.2)
|
||||||
temple (0.7.7)
|
temple (0.7.7)
|
||||||
term-ansicolor (1.4.0)
|
term-ansicolor (1.4.0)
|
||||||
tins (~> 1.0)
|
tins (~> 1.0)
|
||||||
|
@ -463,6 +464,7 @@ DEPENDENCIES
|
||||||
simple-navigation
|
simple-navigation
|
||||||
simple_form
|
simple_form
|
||||||
simplecov
|
simplecov
|
||||||
|
statsd-instrument
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
webmock
|
webmock
|
||||||
will_paginate
|
will_paginate
|
||||||
|
|
11
app/lib/statsd_monitor.rb
Normal file
11
app/lib/statsd_monitor.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class StatsDMonitor
|
||||||
|
def initialize(app)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
|
@ -30,6 +30,8 @@ module Mastodon
|
||||||
|
|
||||||
config.active_job.queue_adapter = :sidekiq
|
config.active_job.queue_adapter = :sidekiq
|
||||||
|
|
||||||
|
config.middleware.insert(0, 'StatsDMonitor')
|
||||||
|
|
||||||
config.middleware.insert_before 0, Rack::Cors do
|
config.middleware.insert_before 0, Rack::Cors do
|
||||||
allow do
|
allow do
|
||||||
origins '*'
|
origins '*'
|
||||||
|
|
|
@ -104,4 +104,8 @@ Rails.application.configure do
|
||||||
config.react.variant = :production
|
config.react.variant = :production
|
||||||
|
|
||||||
config.active_record.logger = nil
|
config.active_record.logger = nil
|
||||||
|
|
||||||
|
config.to_prepare do
|
||||||
|
StatsD.backend = StatsD::Instrument::Backends::NullBackend if ENV['STATSD_ADDR'].blank?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
# inflect.uncountable %w( fish sheep )
|
# inflect.uncountable %w( fish sheep )
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# These inflection rules are supported but not enabled by default:
|
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
inflect.acronym 'StatsD'
|
||||||
# inflect.acronym 'RESTful'
|
end
|
||||||
# end
|
|
||||||
|
|
20
config/initializers/statsd.rb
Normal file
20
config/initializers/statsd.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
StatsD.prefix = 'mastodon'
|
||||||
|
StatsD.default_sample_rate = 1
|
||||||
|
|
||||||
|
StatsDMonitor.extend(StatsD::Instrument)
|
||||||
|
StatsDMonitor.statsd_measure(:call, 'request.duration')
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
Loading…
Reference in a new issue