Class: Haproxy
- Inherits:
-
Object
- Object
- Haproxy
- Includes:
- Graphs::AreaStackedChart, Mongoid::Attributes::Dynamic, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/app/models/haproxy.rb
Class Method Summary collapse
- .chart_data(options = {}) ⇒ Object
- .graphs ⇒ Object
- .haproxy_chart(instance, values) ⇒ Object
- .haproxy_charts(options) ⇒ Object
Class Method Details
.chart_data(options = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/app/models/haproxy.rb', line 11 def self.chart_data( = {}) charts = [] charts = self.haproxy_charts() return charts end |
.graphs ⇒ Object
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() haproxy_instance =[] charts = [] Haproxy.where(:timestamp.gte => [:start]). where(:timestamp.lt => [:end]). where(:host_id => [:host_id]). where(:plugin_id => [: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 |