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 50
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 9
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 35
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 23
def get(status = nil)
  status ? @stats[status] : @stats
end
get_counter(counter = nil) click to toggle source
# File lib/oxidized/node/stats.rb, line 27
def get_counter(counter = nil)
  counter ? @stats[:counter][counter] : @stats[:counter]
end
mtime() click to toggle source
# File lib/oxidized/node/stats.rb, line 39
def mtime
  mtimes.last
end
successes() click to toggle source
# File lib/oxidized/node/stats.rb, line 31
def successes
  @stats[:counter][:success]
end
update_mtime() click to toggle source
# File lib/oxidized/node/stats.rb, line 43
def update_mtime
  @mtimes.push Time.now.utc
  @mtimes.shift
end