Class: ITRP::Cmd_agg_flow
Overview
usage agg proto=11 group_by:nf_routerid,nf_ifindex_out,nf_ifindex_in
Instance Attribute Summary
Attributes inherited from Cmd
#attach_cmd, #children, #enabled_in_state, #trigger
Instance Method Summary collapse
- #completions(patt) ⇒ Object
- #enter(patt) ⇒ Object
-
#initialize(e) ⇒ Cmd_agg_flow
constructor
A new instance of Cmd_agg_flow.
Methods inherited from Cmd
#appstate, #find_node, #is_root?, #place_node, #print_state, #set_time_window, #treeprint
Constructor Details
#initialize(e) ⇒ Cmd_agg_flow
Returns a new instance of Cmd_agg_flow.
6 7 8 9 10 11 |
# File 'lib/handlers/agg_flow.rb', line 6 def initialize (e) super(e) @enabled_in_state = :flow @attach_cmd = '' @trigger = 'agg' end |
Instance Method Details
#completions(patt) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/handlers/agg_flow.rb', line 13 def completions(patt) TRP::AggregateSessionsRequest .fields .collect { |a| a.name.to_s } .grep( /^#{Regexp.escape(patt)}/i) end |
#enter(patt) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/handlers/agg_flow.rb', line 20 def enter(patt) terms = patt.scan( /(\w+)\s*=\s*([\w\-_\.\:,]+)+/ ) qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc} print("Query Params=#{qparams}\n") group_by = patt.scan( /group_by:(\S+)/ ) group_by.flatten! if not group_by.empty? then group_by = group_by[0] else group_by = "" end print("Group By =#{group_by}\n") # meter names req =mk_request(TRP::Message::Command::AGGREGATE_SESSIONS_REQUEST , { :session_group => appstate(:cgguid), :time_interval => appstate(:time_interval), :resolve_keys => true, :group_by_fields => group_by.split(',') }.merge(qparams)) get_response_zmq(@appenv.zmq_endpt,req) do |resp| %w(dest_port nf_routerid nf_ifindex_in nf_ifindex_out ).each do |fieldname| rows = [] rows << resp.send(fieldname).collect do |item| [item.key.key, item.key.readable, item.key.label, item.count, item.metric] end table = Terminal::Table.new( :headings => [fieldname, 'Readable', 'Label', 'Flows', 'Metric' ], :rows => rows.first ) puts(table) end # tags resp.tag_group.each do |tg| puts(tg.group_name) rows = [] rows << tg.tag_metrics.collect do |item| [item.key.key, item.count, item.metric] end table = Terminal::Table.new( :headings => ['Tag', 'Flows', 'Metric' ], :rows => rows.first ) puts(table) end end end |