Class: Gitlab::Metrics::BootTimeTracker

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/gitlab/metrics/boot_time_tracker.rb

Constant Summary collapse

SUPPORTED_RUNTIMES =
[:puma, :sidekiq, :console].freeze

Instance Method Summary collapse

Instance Method Details

#reset!Object



29
30
31
# File 'lib/gitlab/metrics/boot_time_tracker.rb', line 29

def reset!
  @startup_time = nil
end

#startup_timeObject



10
11
12
# File 'lib/gitlab/metrics/boot_time_tracker.rb', line 10

def startup_time
  @startup_time || 0
end

#track_boot_time!(logger: Gitlab::AppJsonLogger) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/metrics/boot_time_tracker.rb', line 14

def track_boot_time!(logger: Gitlab::AppJsonLogger)
  return if @startup_time

  runtime = Gitlab::Runtime.safe_identify
  return unless SUPPORTED_RUNTIMES.include?(runtime)

  @startup_time = Gitlab::Metrics::System.process_runtime_elapsed_seconds

  Gitlab::Metrics.gauge(
    :gitlab_rails_boot_time_seconds, 'Time elapsed for Rails primary process to finish startup'
  ).set({}, @startup_time)

  logger.info(message: 'Application boot finished', runtime: runtime.to_s, duration_s: @startup_time)
end