Class: ITRP::Cmd_toppers

Inherits:
Cmd
  • Object
show all
Defined in:
lib/handlers/toppers.rb

Instance Attribute Summary

Attributes inherited from Cmd

#attach_cmd, #children, #enabled_in_state, #trigger

Instance Method Summary collapse

Methods inherited from Cmd

#appstate, #completions, #find_node, #is_root?, #place_node, #print_state, #set_time_window, #treeprint

Constructor Details

#initialize(e) ⇒ Cmd_toppers

Returns a new instance of Cmd_toppers.



4
5
6
7
8
9
# File 'lib/handlers/toppers.rb', line 4

def initialize (e)
  super(e)
  @enabled_in_state = :counter
  @attach_cmd  = ''
  @trigger = 'toppers'
end

Instance Method Details

#enter(cmdline) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/handlers/toppers.rb', line 11

def enter(cmdline)

  patt = cmdline.scan(/toppers ([0-9]+)/).flatten.first 

  req =TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_GROUP_TOPPER_REQUEST,
     :counter_group => @appenv.context_data[:cgguid],
     :meter => patt.to_i,
     :maxitems => 5,
     :resolve_keys => true,
     :get_key_attributes => true, 
     :time_interval =>  mk_time_interval(@appenv.context_data[:time_window]))

  TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
      print "Counter Group = #{resp.counter_group}\n"
      print "Meter = #{resp.meter}\n"

      rows = [] 
      resp.keys.each do |key|
          attr_str = key.attributes.inject( "") do  |acc,h| 
          acc << "#{h.attr_name}=#{h.attr_value} " 
        end 
          rows << [ key.key,
              key.label,
              key.readable,
              key.metric, attr_str ] 
      end

    table = Terminal::Table.new :headings => ["Key", "Label", "Readable", "Metric"], :rows => rows
    puts(table) 
  end

end