Class: A2A::Monitoring::HealthChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/monitoring.rb

Overview

Health check system

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HealthChecker

Initialize health checker

Parameters:



268
269
270
271
# File 'lib/a2a/monitoring.rb', line 268

def initialize(config)
  @config = config
  @checks = {}
end

Instance Method Details

#check_healthHash

Run all health checks

Returns:

  • (Hash)

    Health check results



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/a2a/monitoring.rb', line 282

def check_health
  results = {}
  overall_status = :healthy

  @checks.each do |name, check|
    result = check.call
    status = result[:status] || :healthy
    results[name] = {
      status: status,
      message: result[:message],
      timestamp: Time.now.iso8601
    }

    overall_status = :unhealthy if status == :unhealthy
  rescue StandardError => e
    results[name] = {
      status: :error,
      message: e.message,
      timestamp: Time.now.iso8601
    }
    overall_status = :unhealthy
  end

  {
    status: overall_status,
    checks: results,
    timestamp: Time.now.iso8601
  }
end

#healthy?Boolean

Check if system is healthy

Returns:

  • (Boolean)


314
315
316
# File 'lib/a2a/monitoring.rb', line 314

def healthy?
  check_health[:status] == :healthy
end

#register_check(name, &check) ⇒ Object

Register a health check

Parameters:

  • name (Symbol)

    Check name

  • check (Proc)

    Check procedure



276
277
278
# File 'lib/a2a/monitoring.rb', line 276

def register_check(name, &check)
  @checks[name] = check
end