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



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

#failuresObject



35
36
37
# 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) ⇒ 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



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

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

#get_counter(counter = nil) ⇒ Object



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

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

#mtimeObject



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

def mtime
  mtimes.last
end

#successesObject



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

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

#update_mtimeObject



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

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