Class: Async::Container::Statistics
- Inherits:
-
Object
- Object
- Async::Container::Statistics
- Defined in:
- lib/async/container/statistics.rb
Overview
Tracks various statistics relating to child instances in a container.
Defined Under Namespace
Classes: Rate
Instance Attribute Summary collapse
-
#failure_rate ⇒ Object
Get the failure rate tracker.
-
#failures ⇒ Object
readonly
How many child instances have failed.
-
#restart_rate ⇒ Object
Get the restart rate tracker.
-
#restarts ⇒ Object
readonly
How many child instances have been restarted.
-
#spawns ⇒ Object
readonly
How many child instances have been spawned.
Instance Method Summary collapse
-
#<<(other) ⇒ Object
Append another statistics instance into this one.
-
#as_json ⇒ Object
Generate a hash representation of the statistics.
-
#failed? ⇒ Boolean
Whether there have been any failures.
-
#failure! ⇒ Object
Increment the number of failures by 1.
-
#initialize(window: 60) ⇒ Statistics
constructor
Initialize the statistics all to 0.
-
#restart! ⇒ Object
Increment the number of restarts by 1.
-
#spawn! ⇒ Object
Increment the number of spawns by 1.
-
#to_json ⇒ Object
Generate a JSON representation of the statistics.
Constructor Details
#initialize(window: 60) ⇒ Statistics
Initialize the statistics all to 0.
77 78 79 80 81 82 83 84 |
# File 'lib/async/container/statistics.rb', line 77 def initialize(window: 60) @spawns = 0 @restarts = 0 @failures = 0 @restart_rate = Rate.new(window: window) @failure_rate = Rate.new(window: window) end |
Instance Attribute Details
#failure_rate ⇒ Object
Get the failure rate tracker.
121 122 123 |
# File 'lib/async/container/statistics.rb', line 121 def failure_rate @failure_rate end |
#failures ⇒ Object (readonly)
How many child instances have failed.
96 97 98 |
# File 'lib/async/container/statistics.rb', line 96 def failures @failures end |
#restart_rate ⇒ Object
Get the restart rate tracker.
117 118 119 |
# File 'lib/async/container/statistics.rb', line 117 def restart_rate @restart_rate end |
#restarts ⇒ Object (readonly)
How many child instances have been restarted.
92 93 94 |
# File 'lib/async/container/statistics.rb', line 92 def restarts @restarts end |
#spawns ⇒ Object (readonly)
How many child instances have been spawned.
88 89 90 |
# File 'lib/async/container/statistics.rb', line 88 def spawns @spawns end |
Instance Method Details
#<<(other) ⇒ Object
Append another statistics instance into this one.
131 132 133 134 135 |
# File 'lib/async/container/statistics.rb', line 131 def << other @spawns += other.spawns @restarts += other.restarts @failures += other.failures end |
#as_json ⇒ Object
Generate a hash representation of the statistics.
140 141 142 143 144 145 146 147 148 |
# File 'lib/async/container/statistics.rb', line 140 def as_json(...) { spawns: @spawns, restarts: @restarts, failures: @failures, restart_rate: @restart_rate.per_second, failure_rate: @failure_rate.per_second, } end |
#failed? ⇒ Boolean
Whether there have been any failures.
125 126 127 |
# File 'lib/async/container/statistics.rb', line 125 def failed? @failures > 0 end |
#failure! ⇒ Object
Increment the number of failures by 1.
110 111 112 113 |
# File 'lib/async/container/statistics.rb', line 110 def failure! @failures += 1 @failure_rate.add(1) end |
#restart! ⇒ Object
Increment the number of restarts by 1.
104 105 106 107 |
# File 'lib/async/container/statistics.rb', line 104 def restart! @restarts += 1 @restart_rate.add(1) end |
#spawn! ⇒ Object
Increment the number of spawns by 1.
99 100 101 |
# File 'lib/async/container/statistics.rb', line 99 def spawn! @spawns += 1 end |
#to_json ⇒ Object
Generate a JSON representation of the statistics.
153 154 155 |
# File 'lib/async/container/statistics.rb', line 153 def to_json(...) as_json.to_json(...) end |