Class: Haproxy

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

Class Method Summary collapse

Class Method Details

.chart_data(options = {}) ⇒ Object



11
12
13
14
15
# File 'lib/app/models/haproxy.rb', line 11

def self.chart_data(options = {})
  charts = []
  charts = self.haproxy_charts(options)
  return charts
end

.graphsObject



51
52
53
54
55
# File 'lib/app/models/haproxy.rb', line 51

def self.graphs
  { 
    :session_per_sec => { :line_color => '#00FFAC', :line_thickness => 4, :title => "session_per_second", :hidden => false},
  }
end

.haproxy_chart(instance, values) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/app/models/haproxy.rb', line 30

def self.haproxy_chart(instance, values)
  chart = self.chart_structure({:title => "Haproxy #{instance}", :value_axis => { :title => "Session per second"} })
  prev = {}
  chart_data = {}
  instances = Hash.new
  values.each do |value|
    instances[value[:stot]] ||= true
    unless prev.has_key?(value[:stot]) then
      prev[value[:stot]] = value
      next
    end
    time_diff = value[:timestamp].to_i - prev[value[:stot]][:timestamp].to_i
    chart[:graph_data] << {
      "timestamp" => value[:timestamp],
      "session_per_sec" => (value[:summary][:stot] - prev[value[:stot]][:summary][:stot]).to_f/time_diff
    }
    prev[value[:stot]] = value
  end
  chart
end

.haproxy_charts(options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/app/models/haproxy.rb', line 17

def self.haproxy_charts(options)
  haproxy_instance =[]
  charts = []
  Haproxy.where(:timestamp.gte => options[:start]).
          where(:timestamp.lt => options[:end]).
          where(:host_id => options[:host_id]).
          where(:plugin_id => options[:plugin_id]).
            order_by(timestamp: :asc).group_by{|u| u[:name]}.each_pair do |instance, values|
              charts << self.haproxy_chart(instance, values)
            end
          return charts
end