Class: A2A::Monitoring::HealthChecker
- Inherits:
-
Object
- Object
- A2A::Monitoring::HealthChecker
- Defined in:
- lib/a2a/monitoring.rb
Overview
Health check system
Instance Method Summary collapse
-
#check_health ⇒ Hash
Run all health checks.
-
#healthy? ⇒ Boolean
Check if system is healthy.
-
#initialize(config) ⇒ HealthChecker
constructor
Initialize health checker.
-
#register_check(name, &check) ⇒ Object
Register a health check.
Constructor Details
#initialize(config) ⇒ HealthChecker
Initialize health checker
268 269 270 271 |
# File 'lib/a2a/monitoring.rb', line 268 def initialize(config) @config = config @checks = {} end |
Instance Method Details
#check_health ⇒ Hash
Run all health checks
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., 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
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
276 277 278 |
# File 'lib/a2a/monitoring.rb', line 276 def register_check(name, &check) @checks[name] = check end |