diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-12-28 13:42:15 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-12-28 13:42:15 +0000 |
commit | 540eb0a9affef14329418b32be0dcd60f2b66e29 (patch) | |
tree | f2562ea6c206c46aedc534497a55fe93f55e97cd /config/initializers | |
parent | c08cb923ec4af9cfb70031259051d5c0c70cad21 (diff) | |
parent | 1be5668ae0e663015d384ea7d8b404f9eeb5b478 (diff) | |
download | gitlab-ce-540eb0a9affef14329418b32be0dcd60f2b66e29.tar.gz |
Merge branch 'influxdb' into 'master'
Storing of application metrics in InfluxDB
This adds support for tracking metrics in InfluxDB, which in turn can be visualized using Grafana. For more information see #2936.
See merge request !2042
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/metrics.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/config/initializers/metrics.rb b/config/initializers/metrics.rb new file mode 100644 index 00000000000..a47d2bf59a6 --- /dev/null +++ b/config/initializers/metrics.rb @@ -0,0 +1,57 @@ +if Gitlab::Metrics.enabled? + require 'influxdb' + require 'socket' + require 'connection_pool' + require 'method_source' + + # These are manually require'd so the classes are registered properly with + # ActiveSupport. + require 'gitlab/metrics/subscribers/action_view' + require 'gitlab/metrics/subscribers/active_record' + + Gitlab::Application.configure do |config| + config.middleware.use(Gitlab::Metrics::RackMiddleware) + end + + Sidekiq.configure_server do |config| + config.server_middleware do |chain| + chain.add Gitlab::Metrics::SidekiqMiddleware + end + end + + # This instruments all methods residing in app/models that (appear to) use any + # of the ActiveRecord methods. This has to take place _after_ initializing as + # for some unknown reason calling eager_load! earlier breaks Devise. + Gitlab::Application.config.after_initialize do + Rails.application.eager_load! + + models = Rails.root.join('app', 'models').to_s + + regex = Regexp.union( + ActiveRecord::Querying.public_instance_methods(false).map(&:to_s) + ) + + Gitlab::Metrics::Instrumentation. + instrument_class_hierarchy(ActiveRecord::Base) do |_, method| + loc = method.source_location + + loc && loc[0].start_with?(models) && method.source =~ regex + end + end + + Gitlab::Metrics::Instrumentation.configure do |config| + config.instrument_instance_methods(Gitlab::Shell) + + config.instrument_methods(Gitlab::Git) + + Gitlab::Git.constants.each do |name| + const = Gitlab::Git.const_get(name) + + config.instrument_methods(const) if const.is_a?(Module) + end + end + + GC::Profiler.enable + + Gitlab::Metrics::Sampler.new.start +end |