Class: Bsdnet::BytesInOut

Inherits:
Object
  • Object
show all
Includes:
Graphs::AreaNotStackedChart, Mongoid::Attributes::Dynamic, Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/app/models/bsdnet/bytes_in_out.rb

Class Method Summary collapse

Class Method Details

.bytes_chart(options) ⇒ Object



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
# File 'lib/app/models/bsdnet/bytes_in_out.rb', line 19

def self.bytes_chart(options)
  chart = self.chart_structure({:title => "Network traffic in/out", :value_axis => { :title => "Network traffic [Bytes]"}})
  #TODO - sort by date
  values = Bsdnet::BytesInOut.where(:timestamp.gte => options[:start]).
                              where(:timestamp.lt => options[:end]).
		where(:host_id => options[:host_id]).
		where(:plugin_id => options[:plugin_id]).
		order(timestamp: :asc)
  prev = nil
  values.each do |data|
    if prev.nil?
      prev = data
      next
    end
    bytes_in_per_sec = (data[:bytes_in_v4] - prev[:bytes_in_v4])/(data[:timestamp] - prev[:timestamp])
    bytes_out_per_sec = (data[:bytes_out_v4] - prev[:bytes_out_v4])/(data[:timestamp] - prev[:timestamp])
    chart[:graph_data] << {
      :timestamp => data[:timestamp],
      :bytes_out => bytes_out_per_sec.to_i,
      :bytes_in => bytes_in_per_sec.to_i
    }
    prev = data
  end

  chart
end

.chart_data(options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/app/models/bsdnet/bytes_in_out.rb', line 11

def self.chart_data(options = {})
  charts = []
  options[:interface] = 'vlan254'
  charts << self.bytes_chart(options)
  #TODO interfaces??
  return charts
end

.graphsObject



46
47
48
49
50
51
# File 'lib/app/models/bsdnet/bytes_in_out.rb', line 46

def self.graphs
  {
    :bytes_in => { :line_color => '#FF3300' },
    :bytes_out => {:line_color => '#00FF00' }
  }
end