Module: SflowCollector::Collector

Defined in:
lib/sflow/lib/sflow/collector.rb

Instance Method Summary collapse

Instance Method Details

#post_initObject



5
6
7
# File 'lib/sflow/lib/sflow/collector.rb', line 5

def post_init
  puts "Server listening."
end

#receive_data(data) ⇒ Object



9
10
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
# File 'lib/sflow/lib/sflow/collector.rb', line 9

def receive_data(data)
  operation = proc do
    begin
      if data != nil
        sflow = SflowParser.parse_packet(data)
      end
    rescue Exception => e
      puts Time.now
      puts sflow.inspect
      puts e.message
      puts e.backtrace
    end
  end

  callback = proc do |sflow|
    begin
      if sflow != nil
        SflowStorage.send_udpjson(sflow)
      end
    rescue Exception => e
      puts Time.now
      puts sflow.inspect if sflow != nil
      puts e.message
      puts e.backtrace
    end
  end

  EM.defer(operation,callback)

end