Class: LitmusPaper::Metric::SocketUtilization

Inherits:
Object
  • Object
show all
Defined in:
lib/litmus_paper/metric/socket_utilization.rb

Direct Known Subclasses

TcpSocketUtilization, UnixSocketUtilization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weight, maxconn) ⇒ SocketUtilization

Returns a new instance of SocketUtilization.



8
9
10
11
# File 'lib/litmus_paper/metric/socket_utilization.rb', line 8

def initialize(weight, maxconn)
  @weight = weight
  @maxconn = maxconn
end

Instance Attribute Details

#maxconnObject (readonly)

Returns the value of attribute maxconn.



6
7
8
# File 'lib/litmus_paper/metric/socket_utilization.rb', line 6

def maxconn
  @maxconn
end

#weightObject (readonly)

Returns the value of attribute weight.



6
7
8
# File 'lib/litmus_paper/metric/socket_utilization.rb', line 6

def weight
  @weight
end

Instance Method Details

#_statsObject



39
40
41
# File 'lib/litmus_paper/metric/socket_utilization.rb', line 39

def _stats
  raise "Sub-classes must implement _stats"
end

#current_healthObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/litmus_paper/metric/socket_utilization.rb', line 13

def current_health
  stats = _stats

  if stats.queued == 0
    return weight
  end

  [
    weight - (
      (weight * stats.active.to_f) / (3 * maxconn.to_f) +
      (2 * weight * stats.queued.to_f) / (3 * maxconn.to_f)
    ),
    1
  ].max
end

#statsObject



29
30
31
32
33
34
35
36
37
# File 'lib/litmus_paper/metric/socket_utilization.rb', line 29

def stats
  stats = _stats

  {
    :socket_active => stats.active,
    :socket_queued => stats.queued,
    :socket_utilization => ((stats.queued / maxconn.to_f) * 100).round,
  }
end

#to_sObject



43
44
45
# File 'lib/litmus_paper/metric/socket_utilization.rb', line 43

def to_s
  raise "Sub-classes must implement to_s"
end