Class: AgentHarness::Orchestration::Metrics
- Inherits:
-
Object
- Object
- AgentHarness::Orchestration::Metrics
- Defined in:
- lib/agent_harness/orchestration/metrics.rb
Overview
Collects and aggregates orchestration metrics
Tracks attempts, successes, failures, and timing information for provider orchestration.
Instance Method Summary collapse
-
#initialize ⇒ Metrics
constructor
A new instance of Metrics.
-
#provider_metrics(provider_name) ⇒ Hash
Get metrics for a specific provider.
-
#record_attempt(provider_name) ⇒ void
Record an attempt for a provider.
-
#record_failure(provider_name, error) ⇒ void
Record a failure for a provider.
-
#record_success(provider_name, duration) ⇒ void
Record a success for a provider.
-
#record_switch(from_provider, to_provider, reason) ⇒ void
Record a provider switch.
-
#reset! ⇒ void
Reset all metrics.
-
#summary ⇒ Hash
Get metrics summary.
Constructor Details
#initialize ⇒ Metrics
Returns a new instance of Metrics.
10 11 12 13 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 10 def initialize @mutex = Mutex.new reset! end |
Instance Method Details
#provider_metrics(provider_name) ⇒ Hash
Get metrics for a specific provider
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 99 def provider_metrics(provider_name) provider = provider_name.to_sym @mutex.synchronize do { attempts: @attempts[provider], successes: @successes[provider], failures: @failures[provider], success_rate: provider_success_rate(provider), average_duration: average_duration(provider) } end end |
#record_attempt(provider_name) ⇒ void
This method returns an undefined value.
Record an attempt for a provider
19 20 21 22 23 24 25 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 19 def record_attempt(provider_name) @mutex.synchronize do provider = provider_name.to_sym @attempts[provider] += 1 @total_attempts += 1 end end |
#record_failure(provider_name, error) ⇒ void
This method returns an undefined value.
Record a failure for a provider
47 48 49 50 51 52 53 54 55 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 47 def record_failure(provider_name, error) @mutex.synchronize do provider = provider_name.to_sym @failures[provider] += 1 @total_failures += 1 @error_counts[error.class.name] += 1 @last_failure_time = Time.now end end |
#record_success(provider_name, duration) ⇒ void
This method returns an undefined value.
Record a success for a provider
32 33 34 35 36 37 38 39 40 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 32 def record_success(provider_name, duration) @mutex.synchronize do provider = provider_name.to_sym @successes[provider] += 1 @total_successes += 1 @durations[provider] << duration @last_success_time = Time.now end end |
#record_switch(from_provider, to_provider, reason) ⇒ void
This method returns an undefined value.
Record a provider switch
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 63 def record_switch(from_provider, to_provider, reason) @mutex.synchronize do @switches << { from: from_provider.to_sym, to: to_provider.to_sym, reason: reason, timestamp: Time.now } @total_switches += 1 end end |
#reset! ⇒ void
This method returns an undefined value.
Reset all metrics
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 115 def reset! @mutex.synchronize do @attempts = Hash.new(0) @successes = Hash.new(0) @failures = Hash.new(0) @durations = Hash.new { |h, k| h[k] = [] } @error_counts = Hash.new(0) @switches = [] @total_attempts = 0 @total_successes = 0 @total_failures = 0 @total_switches = 0 @last_success_time = nil @last_failure_time = nil end end |
#summary ⇒ Hash
Get metrics summary
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/agent_harness/orchestration/metrics.rb', line 78 def summary @mutex.synchronize do { total_attempts: @total_attempts, total_successes: @total_successes, total_failures: @total_failures, total_switches: @total_switches, success_rate: success_rate, by_provider: provider_summary, error_counts: @error_counts.dup, last_success_time: @last_success_time, last_failure_time: @last_failure_time, recent_switches: @switches.last(10) } end end |