Class: ITRP::Cmd_traffic

Inherits:
Cmd
  • Object
show all
Defined in:
lib/handlers/traffic.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_traffic

Returns a new instance of Cmd_traffic.



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

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

Instance Method Details

#enter(cmdline) ⇒ Object



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
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
# File 'lib/handlers/traffic.rb', line 13

def enter(cmdline)

       patt = cmdline.scan(/traffic\s+(.*)/).flatten

	p patt 

	use_key = patt.empty? ? appstate(:cgkey)  : patt[0]

	# meter names 
	req =mk_request(TRP::Message::Command::COUNTER_GROUP_INFO_REQUEST,
					 :counter_group => @appenv.context_data[:cgguid],
					 :get_meter_info => true )

	colnames   = ["Timestamp"]
	get_response_zmq(@appenv.zmq_endpt,req) do |resp|
		  resp.group_details.each do |group_detail|
		  	group_detail.meters.each do |meter|
				colnames  <<  meter.units  
			end
		  end
	end


	req =TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_ITEM_REQUEST,
		 :counter_group => @appenv.context_data[:cgguid],
		 :key => use_key, 
		 :get_key_attributes=>true,
		 :time_interval =>  appstate( :time_interval) ) 

	rows  = [] 

	print "Request sent at  #{Time.now}\n"

	totals = nil 
	TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
		  print "Counter Group = #{resp.counter_group}\n"
		  print "Key           = #{resp.key.key}\n"
		  print "Readable      = #{resp.key.readable}\n"
		  print "Label         = #{resp.key.label}\n"
		  print "Description   = #{resp.key.description}\n"
		  print "Num intervals = #{resp.stats.size}\n"

		  # attribute strings 
		  attr_str = resp.key.attributes.inject( "") do  |acc,h| 
			acc << "#{h.attr_name}=#{h.attr_value} " 
		  end 
		  print "Attributes    = #{attr_str}\n"

		  print "Response at  #{Time.now}\n"


		  resp.stats.each do |tsval|
		  		if totals.nil? 
					totals = tsval.values
				else 
				  totals = [totals, tsval.values ].transpose.map {|x| x.reduce(:+)}
				end 
			  rows << [ Time.at(tsval.ts_tv_sec), tsval.values  ].flatten 
		  end

		  table = Terminal::Table.new(:headings => colnames,  :rows => rows )
		  puts(table) 
		  totalstable = Terminal::Table.new(:headings => colnames,  :rows => [totals.unshift(0).collect{|a| a*60}])
		  puts(totalstable) 
	end

end