class Statistics
Tracks various statistics relating to child instances in a container.
Nested
Definitions
def initialize(window: 60)
Initialize the statistics all to 0.
Signature
-
parameter
windowInteger The time window in seconds for rate calculations.
Implementation
def initialize(window: 60)
@spawns = 0
@restarts = 0
@failures = 0
@restart_rate = Rate.new(window: window)
@failure_rate = Rate.new(window: window)
end
attr :spawns
How many child instances have been spawned.
Signature
-
attribute
Integer
attr :restarts
How many child instances have been restarted.
Signature
-
attribute
Integer
attr :failures
How many child instances have failed.
Signature
-
attribute
Integer
def spawn!
Increment the number of spawns by 1.
Implementation
def spawn!
@spawns += 1
end
def restart!
Increment the number of restarts by 1.
Implementation
def restart!
@restarts += 1
@restart_rate.add(1)
end
def failure!
Increment the number of failures by 1.
Implementation
def failure!
@failures += 1
@failure_rate.add(1)
end
attr :restart_rate
Get the restart rate tracker.
Signature
-
attribute
Rate
attr :failure_rate
Get the failure rate tracker.
Signature
-
attribute
Rate
def failed?
Whether there have been any failures.
Signature
-
returns
Boolean If the failure count is greater than 0.
Implementation
def failed?
@failures > 0
end
def <<(other)
Append another statistics instance into this one.
Signature
-
parameter
otherStatistics The statistics to append.
Implementation
def << other
@spawns += other.spawns
@restarts += other.restarts
@failures += other.failures
end
def as_json(...)
Generate a hash representation of the statistics.
Signature
-
returns
Hash The statistics as a hash.
Implementation
def as_json(...)
{
spawns: @spawns,
restarts: @restarts,
failures: @failures,
restart_rate: @restart_rate.per_second,
failure_rate: @failure_rate.per_second,
}
end
def to_json(...)
Generate a JSON representation of the statistics.
Signature
-
returns
String The statistics as JSON.
Implementation
def to_json(...)
as_json.to_json(...)
end