Class: Simple::Metrics::Check

Inherits:
Java::ComYammerMetricsCore::HealthCheck
  • Object
show all
Defined in:
lib/simple/metrics/healthcheck.rb

Instance Method Summary (collapse)

Constructor Details

- (Check) initialize(name, &blk)

A new instance of Check



38
39
40
41
# File 'lib/simple/metrics/healthcheck.rb', line 38

def initialize(name, &blk)
  super(name)
  @blk = blk
end

Instance Method Details

- (Object) check

Call the block and capture the return value. If the result is `Simple::Metrics::HEALTHY`, mark the healthcheck as healthy. If the result is a `Simple::Metrics::WARNING`, mark the healthcheck in the warning state. If the result is a `Simple::Metrics::UNHEALTHY`, or throws an error, mark the healthcheck as unhealthy.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/simple/metrics/healthcheck.rb', line 48

def check
  begin
    r = @blk.call
    case (r.is_a?(Class) ? r.new : r)
    when Simple::Metrics::HEALTHY
      Java::ComYammerMetricsCore::HealthCheck::Result.healthy
    when Simple::Metrics::WARNING
      Java::ComYammerMetricsCore::HealthCheck::Result.warning
    when Simple::Metrics::UNHEALTHY
      Java::ComYammerMetricsCore::HealthCheck::Result.unhealthy(r.message)
    end
  rescue StandardError => e
    Java::ComYammerMetricsCore::HealthCheck::Result.unhealthy(e.message)
  end
end