Module: Simple::Metrics::Healthchecks

Includes:
Simple::Metrics
Defined in:
lib/simple/metrics/healthcheck.rb

Constant Summary

Constants included from Simple::Metrics

DEFAULT_DURATION_UNIT, DEFAULT_RATE_UNIT, DEFAULT_TIMING_UNIT, VERSION

Instance Method Summary collapse

Methods included from Simple::Metrics

#metrics_registry, #new_metric_name, #sanitize_classname

Methods included from Timer

#timer

Instance Method Details

#new_healthcheck(name, &blk) ⇒ MetricName

Create a new healthcheck

Parameters:

  • name (String)

    The name of the healthcheck, eg ‘check_db`.

Returns:

  • (MetricName)

    the newly created metric name



12
13
14
15
16
# File 'lib/simple/metrics/healthcheck.rb', line 12

def new_healthcheck(name, &blk)
  healthcheck = Check.new(name, &blk)
  Java::ComYammerMetrics::HealthChecks.register(healthcheck)
  run_healthcheck_loop
end

#run_all_healthchecksObject

Run all of the healthchecks that have been defined



32
33
34
# File 'lib/simple/metrics/healthcheck.rb', line 32

def run_all_healthchecks
  Java::ComYammerMetrics::HealthChecks.runHealthChecks
end

#run_healthcheck_loopObject

Run the healthcheck loop This starts a new thread that runs all of the defined healthcheck loops.



20
21
22
23
24
25
26
27
28
29
# File 'lib/simple/metrics/healthcheck.rb', line 20

def run_healthcheck_loop
  return if @running_healthcheck_loop
  Thread.new do
    loop do
      run_all_healthchecks
      sleep 5
    end
  end
  @running_healthcheck_loop = true
end