Class: AllQ::Stats

Inherits:
Base
  • Object
show all
Defined in:
lib/allq/actions/stats.rb

Constant Summary

Constants inherited from Base

Base::ALLQ_DEBUG_DATA

Instance Attribute Summary

Attributes inherited from Base

#client, #connection

Instance Method Summary collapse

Methods inherited from Base

#build_job, #initialize, #send_hash_as_json

Constructor Details

This class inherits a constructor from AllQ::Base

Instance Method Details

#base_send(_data) ⇒ Object



55
56
57
58
59
60
# File 'lib/allq/actions/stats.rb', line 55

def base_send(_data)
  {
    'action' => 'stats',
    'params' => {}
  }
end

#breakout(results) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/allq/actions/stats.rb', line 40

def breakout(results)
  results.each do |server, s_data|
    s_data.delete('global')
    s_data.each do |tube, tube_data|
      interize(tube_data)
    end
  end
  results
end

#interize(hash) ⇒ Object



50
51
52
53
# File 'lib/allq/actions/stats.rb', line 50

def interize(hash)
  return {} if hash.nil? || hash.empty?
  hash.update(hash){ |_, v| v.to_i }
end

#merge_tube_data(original_hash, new_hash) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/allq/actions/stats.rb', line 29

def merge_tube_data(original_hash, new_hash)
  if original_hash.nil?
    original_hash = {}
  end
  interize(new_hash)
  new_hash.each do |k, v|
    original_hash[k] = original_hash[k].to_i + v
  end
  original_hash
end

#rcv(data) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/allq/actions/stats.rb', line 15

def rcv(data)
  return nil if data.to_s == '' || data.to_s.strip == '{}'
  results = JSON.parse(data)
  stats = {}
  return breakout(results) if @breakout

  results.each do |server, s_data|
    s_data.each do |tube, tube_data|
      stats[tube] = merge_tube_data(stats[tube], tube_data)
    end
  end
  stats
end

#setupObject



4
5
# File 'lib/allq/actions/stats.rb', line 4

def setup
end

#snd(data) ⇒ Object



7
8
9
10
11
12
# File 'lib/allq/actions/stats.rb', line 7

def snd(data)
  send_data = base_send(data)
  @breakout = data ? data[:breakout].to_s == "true" : false
  response = send_hash_as_json(send_data, true)
  rcv(response)
end