Class: Oxidized::Node::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/oxidized/node/stats.rb

Constant Summary collapse

MAX_STAT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mtimesObject (readonly)

Returns the value of attribute mtimes.



4
5
6
# File 'lib/oxidized/node/stats.rb', line 4

def mtimes
  @mtimes
end

Instance Method Details

#add(job) ⇒ void

This method returns an undefined value.

Parameters:

  • job (Job)

    job whose information add to stats



10
11
12
13
14
15
16
17
18
19
20
# 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

#failuresObject



36
37
38
# 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) ⇒ Hash, Array

Returns Hash of stats for every status or Array of stats for specific status.

Parameters:

  • status (Symbol) (defaults to: nil)

    stats for specific status

Returns:

  • (Hash, Array)

    Hash of stats for every status or Array of stats for specific status



24
25
26
# File 'lib/oxidized/node/stats.rb', line 24

def get(status = nil)
  status ? @stats[status] : @stats
end

#get_counter(counter = nil) ⇒ Object



28
29
30
# File 'lib/oxidized/node/stats.rb', line 28

def get_counter(counter = nil)
  counter ? @stats[:counter][counter] : @stats[:counter]
end

#mtimeObject



40
41
42
# File 'lib/oxidized/node/stats.rb', line 40

def mtime
  mtimes.last
end

#successesObject



32
33
34
# File 'lib/oxidized/node/stats.rb', line 32

def successes
  @stats[:counter][:success]
end

#update_mtimeObject



44
45
46
47
# File 'lib/oxidized/node/stats.rb', line 44

def update_mtime
  @mtimes.push Time.now.utc
  @mtimes.shift
end