Class: Healthchecker::MetricsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/healthchecker/metrics_controller.rb

Defined Under Namespace

Modules: ConfigurableMetrics

Instance Method Summary collapse

Instance Method Details

#current_statusObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/healthchecker/metrics_controller.rb', line 8

def current_status
  Healthchecker.configuration.metrics.reduce(uptime) { |status, metric|
    if ConfigurableMetrics.method_defined? metric
      status = status.merge(ConfigurableMetrics.send metric)
    else
      supported_metrics = ConfigurableMetrics.public_instance_methods
      message = "#{metric} is not a supported metric. Supported metrics are #{supported_metrics}"
      raise Healthchecker::ConfigurationError, message
    end
    status
  }
end

#showObject



4
5
6
# File 'app/controllers/healthchecker/metrics_controller.rb', line 4

def show
  render json: current_status
end

#uptimeObject



21
22
23
24
25
# File 'app/controllers/healthchecker/metrics_controller.rb', line 21

def uptime
  {
    uptime: Time.now - Healthchecker::APPLICATION_STARTED_AT
  }
end