class Oxidized::Node::Stats
Constants
- MAX_STAT
Attributes
mtimes[R]
Public Class Methods
new()
click to toggle source
# File lib/oxidized/node/stats.rb, line 51 def initialize @history_size = Oxidized.config.stats.history_size? || MAX_STAT @mtimes = Array.new(@history_size, "unknown") @stats = {} @stats[:counter] = Hash.new 0 end
Public Instance Methods
add(job)
click to toggle source
@param [Job] job job whose information add to stats @return [void]
# File lib/oxidized/node/stats.rb, line 10 def add(job) stat = { start: job.start, end: job.end, time: job.time } @stats[job.status] ||= [] @stats[job.status].shift if @stats[job.status].size > @history_size @stats[job.status].push stat @stats[:counter][job.status] += 1 end
failures()
click to toggle source
# File lib/oxidized/node/stats.rb, line 36 def failures @stats[:counter].reduce(0) { |m, h| h[0] == :success ? m : m + h[1] } end
get(status = nil)
click to toggle source
@param [Symbol] status stats for specific status @return [Hash,Array] Hash of stats for every status or Array of stats for specific status
# File lib/oxidized/node/stats.rb, line 24 def get(status = nil) status ? @stats[status] : @stats end
get_counter(counter = nil)
click to toggle source
# File lib/oxidized/node/stats.rb, line 28 def get_counter(counter = nil) counter ? @stats[:counter][counter] : @stats[:counter] end
mtime()
click to toggle source
# File lib/oxidized/node/stats.rb, line 40 def mtime mtimes.last end
successes()
click to toggle source
# File lib/oxidized/node/stats.rb, line 32 def successes @stats[:counter][:success] end
update_mtime()
click to toggle source
# File lib/oxidized/node/stats.rb, line 44 def update_mtime @mtimes.push Time.now.utc @mtimes.shift end