Class: Promenade::Raindrops::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/promenade/raindrops/stats.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener_address: nil) ⇒ Stats

Returns a new instance of Stats.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/promenade/raindrops/stats.rb', line 20

def initialize(listener_address: nil)
  return unless defined?(::Raindrops)
  return unless defined?(::Raindrops::Linux.tcp_listener_stats)

  @listener_address = listener_address || "127.0.0.1:#{ENV.fetch('PORT', 3000)}"

  stats = ::Raindrops::Linux.tcp_listener_stats([@listener_address])[@listener_address]

  @active_workers = stats.active
  @queued_requests = stats.queued
end

Instance Attribute Details

#active_workersObject (readonly)

Returns the value of attribute active_workers.



18
19
20
# File 'lib/promenade/raindrops/stats.rb', line 18

def active_workers
  @active_workers
end

#listener_addressObject (readonly)

Returns the value of attribute listener_address.



18
19
20
# File 'lib/promenade/raindrops/stats.rb', line 18

def listener_address
  @listener_address
end

#queued_requestsObject (readonly)

Returns the value of attribute queued_requests.



18
19
20
# File 'lib/promenade/raindrops/stats.rb', line 18

def queued_requests
  @queued_requests
end

Class Method Details

.instrument(listener_address: nil) ⇒ Object



37
38
39
# File 'lib/promenade/raindrops/stats.rb', line 37

def self.instrument(listener_address: nil)
  new(listener_address: listener_address).instrument
end

Instance Method Details

#instrumentObject



32
33
34
35
# File 'lib/promenade/raindrops/stats.rb', line 32

def instrument
  Promenade.metric(:rack_active_workers).set({}, active_workers) if active_workers
  Promenade.metric(:rack_queued_requests).set({}, queued_requests) if queued_requests
end