Class: Oxidized::Node::Stats
- Inherits:
-
Object
- Object
- Oxidized::Node::Stats
- Defined in:
- lib/oxidized/node/stats.rb
Constant Summary collapse
- MAX_STAT =
10
Instance Attribute Summary collapse
-
#mtimes ⇒ Object
readonly
Returns the value of attribute mtimes.
Instance Method Summary collapse
- #add(job) ⇒ void
- #failures ⇒ Object
-
#get(status = nil) ⇒ Hash, Array
Hash of stats for every status or Array of stats for specific status.
- #get_counter(counter = nil) ⇒ Object
- #mtime ⇒ Object
- #successes ⇒ Object
- #update_mtime ⇒ Object
Instance Attribute Details
#mtimes ⇒ Object (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.
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 |
#failures ⇒ Object
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.
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 |
#mtime ⇒ Object
39 40 41 |
# File 'lib/oxidized/node/stats.rb', line 39 def mtime mtimes.last end |
#successes ⇒ Object
31 32 33 |
# File 'lib/oxidized/node/stats.rb', line 31 def successes @stats[:counter][:success] end |
#update_mtime ⇒ Object
43 44 45 46 |
# File 'lib/oxidized/node/stats.rb', line 43 def update_mtime @mtimes.push Time.now.utc @mtimes.shift end |