14 | | == 2.1 !OpenFlow Statistics Measurement == |
15 | | |
16 | | ofcollect.rb |
17 | | {{{ |
18 | | |
19 | | #!/usr/bin/env ruby |
20 | | require 'rubygems' |
21 | | require 'oml4r' |
22 | | require 'file-tail' |
23 | | APPNAME = "ofstats" |
24 | | class MPThroughput < OML4R::MPBase |
25 | | name :ofthroughput |
26 | | param :pathtype, :type => :string |
27 | | param :numflows, :type => :int64 |
28 | | param :numbytes, :type => :int64 |
29 | | param :numpacket, :type => :int64 |
30 | | param :throughput, :type => :int64 |
31 | | param :units, :type => :string |
32 | | param :instput, :type => :int64 |
33 | | param :units2, :type => :string |
34 | | end |
35 | | class OFStatsWrapper |
36 | | def initialize(args) |
37 | | @addr = nil |
38 | | @if_num = ' ' |
39 | | @trema_port = ' ' |
40 | | @trema_path = ' ' |
41 | | @verbose = true |
42 | | @numeric = ' ' |
43 | | OML4R::init(args, :appName => "#{APPNAME}_wrapper", :domain => 'foo', :collect => 'file:-') { |argParser| |
44 | | argParser.banner = "Reports OpenFlow stat measurements via OML\n\n" |
45 | | argParser.on("-f" , "--file_path ADDRESS", "Path where output is saved"){ |address| @addr = address } |
46 | | argParser.on("-i","--interface IFNUM","Interface number"){ |if_num| @if_num ="#{if_num.to_i()}" } |
47 | | argParser.on("-q", "--no-quiet ","Don't show of stats output on console"){ @verbose = false } |
48 | | argParser.on("-n", "--[no]-numeric ", "No attempt twill be made to look up symbolic names for host addresses"){ @numeric ='-n' } |
49 | | } |
50 | | unless @addr !=nil |
51 | | raise "You did not specify path of file (-p option)" |
52 | | end |
53 | | end |
54 | | class MyFile < File |
55 | | include File::Tail |
56 | | end |
57 | | def start() |
58 | | log = MyFile.new("#{@addr}") |
59 | | log.interval = @if_num |
60 | | log.backward(10) |
61 | | puts "#{@if_num}" |
62 | | log.tail { |line| print line |
63 | | processOutput(line) |
64 | | } |
65 | | end |
66 | | def processOutput(output) |
67 | | column = output.split(" ") |
68 | | puts "Each line process" |
69 | | # Inject the measurements into OML |
70 | | MPThroughput.inject("#{column[0]}", column[1], column[2], |
71 | | column[3], column[4], "#{column[5]}", |
72 | | column[6], "#{column[7]}") |
73 | | end |
74 | | end |
75 | | begin |
76 | | app = OFStatsWrapper.new(ARGV) |
77 | | app.start() |
78 | | rescue SystemExit |
79 | | rescue SignalException |
80 | | puts "OFWrapper stopped." |
81 | | rescue Exception => ex |
82 | | puts "Error - When executing the wrapper application!" |
83 | | puts "Error - Type: #{ex.class}" |
84 | | puts "Error - Message: #{ex}\n\n" |
85 | | # Uncomment the next line to get more info on errors |
86 | | # puts "Trace - #{ex.backtrace.join("\n\t")}" |
87 | | end |
88 | | OML4R::close() |
89 | | # Local Variables: |
90 | | # mode:ruby |
91 | | # End: |
92 | | # vim: ft=ruby:sw=2 |
93 | | }}} |
94 | | |
95 | | OEDL script |
96 | | {{{ |
97 | | |
98 | | defProperty('source1', "nowcastbox-sdxdemo", "ID of a resource") |
99 | | defProperty('intervalcol',"1", "Interval to Tail") |
100 | | |
101 | | defProperty('pathfile', "/tmp/flowstats.out", "Path to file") |
102 | | |
103 | | |
104 | | |
105 | | defApplication('ofstats') do |app| |
106 | | app.description = 'Simple Definition for the of-collect application' |
107 | | # Define the path to the binary executable for this application |
108 | | app.binary_path = '/usr/local/bin/ofcollect.rb' |
109 | | app.defProperty('target', 'Address to output file', '-f', {:type => :string}) |
110 | | app.defProperty("interval","Interval",'-i', {:type => :string}) |
111 | | app.defMeasurement('wrapper_ofthroughput') do |m| |
112 | | m.defMetric(':pathtype', :string) |
113 | | m.defMetric('throughput',:int64) |
114 | | m.defMetric('instput',:int64) |
115 | | end |
116 | | end |
117 | | defGroup('Source1', property.source1) do |node| |
118 | | node.addApplication("ofstats") do |app| |
119 | | app.setProperty('target', property.pathfile) |
120 | | app.setProperty('interval', property.intervalcol) |
121 | | app.measure('wrapper_ofthroughput', :samples => 1) |
122 | | end |
123 | | end |
124 | | |
125 | | |
126 | | onEvent(:ALL_UP_AND_INSTALLED) do |event| |
127 | | info "Starting the collect" |
128 | | after 2 do |
129 | | group('Source1').startApplications |
130 | | end |
131 | | after 800 do |
132 | | info "Stopping the collect" |
133 | | allGroups.stopApplications |
134 | | Experiment.done |
135 | | end |
136 | | end |
137 | | |
138 | | defGraph 'Throughput' do |g| |
139 | | g.ms('wrapper_ofthroughput').select(:oml_ts_client, :throughput, :pathtype) |
140 | | g.caption "Throughput of Flows" |
141 | | g.type 'line_chart3' |
142 | | g.mapping :x_axis => :oml_ts_client, :y_axis => :throughput, :group_by => :pathtype |
143 | | g.xaxis :legend => 'oml_ts' |
144 | | g.yaxis :legend => 'Throughput', :ticks => {:format => 's'} |
145 | | end |
146 | | defGraph 'InstantaneousThroughput' do |g| |
147 | | g.ms('wrapper_ofthroughput').select(:oml_ts_client, :instput, :pathtype) |
148 | | g.caption "Throughput of Flows" |
149 | | g.type 'line_chart3' |
150 | | g.mapping :x_axis => :oml_ts_client, :y_axis => :instput, :group_by => :pathtype |
151 | | g.xaxis :legend => 'oml_ts' |
152 | | g.yaxis :legend => 'Instantaneous Throughput', :ticks => {:format => 's'} |
153 | | end |
154 | | |
155 | | }}} |
156 | | |