diff options
Diffstat (limited to 'lib/raindrops')
-rw-r--r-- | lib/raindrops/aggregate.rb | 1 | ||||
-rw-r--r-- | lib/raindrops/aggregate/last_data_recv.rb | 24 | ||||
-rw-r--r-- | lib/raindrops/aggregate/pmq.rb | 1 | ||||
-rw-r--r-- | lib/raindrops/last_data_recv.rb | 1 | ||||
-rw-r--r-- | lib/raindrops/linux.rb | 1 | ||||
-rw-r--r-- | lib/raindrops/middleware.rb | 14 | ||||
-rw-r--r-- | lib/raindrops/middleware/proxy.rb | 1 | ||||
-rw-r--r-- | lib/raindrops/struct.rb | 1 | ||||
-rw-r--r-- | lib/raindrops/watcher.rb | 1 |
9 files changed, 35 insertions, 10 deletions
diff --git a/lib/raindrops/aggregate.rb b/lib/raindrops/aggregate.rb index 4fb731f..9ed7eb7 100644 --- a/lib/raindrops/aggregate.rb +++ b/lib/raindrops/aggregate.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # # raindrops may use the {aggregate}[https://github.com/josephruscio/aggregate] # RubyGem to aggregate statistics from TCP_Info lookups. diff --git a/lib/raindrops/aggregate/last_data_recv.rb b/lib/raindrops/aggregate/last_data_recv.rb index 6919fbc..2205208 100644 --- a/lib/raindrops/aggregate/last_data_recv.rb +++ b/lib/raindrops/aggregate/last_data_recv.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "socket" # # @@ -10,6 +11,8 @@ require "socket" # Methods wrapped include: # - TCPServer#accept # - TCPServer#accept_nonblock +# - Socket#accept +# - Socket#accept_nonblock # - Kgio::TCPServer#kgio_accept # - Kgio::TCPServer#kgio_tryaccept module Raindrops::Aggregate::LastDataRecv @@ -33,8 +36,10 @@ module Raindrops::Aggregate::LastDataRecv # automatically extends any TCPServer objects used by Unicorn def self.cornify! - Unicorn::HttpServer::LISTENERS.each do |sock| - sock.extend(self) if TCPServer === sock + Unicorn::HttpServer::LISTENERS.each do |s| + if TCPServer === s || (s.instance_of?(Socket) && s.local_address.ip?) + s.extend(self) + end end end @@ -60,8 +65,8 @@ module Raindrops::Aggregate::LastDataRecv count! super end - def accept_nonblock - count! super + def accept_nonblock(exception: true) + count! super(exception: exception) end # :startdoc: @@ -72,12 +77,19 @@ module Raindrops::Aggregate::LastDataRecv # # We require TCP_DEFER_ACCEPT on the listen socket for # +last_data_recv+ to be accurate - def count!(io) + def count!(ret) + case ret + when :wait_readable + when Array # Socket#accept_nonblock + io = ret[0] + else # TCPSocket#accept_nonblock + io = ret + end if io x = Raindrops::TCP_Info.new(io) @raindrops_aggregate << x.last_data_recv end - io + ret end end diff --git a/lib/raindrops/aggregate/pmq.rb b/lib/raindrops/aggregate/pmq.rb index 64d0a4f..94bdf4f 100644 --- a/lib/raindrops/aggregate/pmq.rb +++ b/lib/raindrops/aggregate/pmq.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "tempfile" require "aggregate" require "posix_mq" diff --git a/lib/raindrops/last_data_recv.rb b/lib/raindrops/last_data_recv.rb index b4808a1..e6c47e1 100644 --- a/lib/raindrops/last_data_recv.rb +++ b/lib/raindrops/last_data_recv.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "raindrops" # This is highly experimental! diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb index 9842ae1..a76192c 100644 --- a/lib/raindrops/linux.rb +++ b/lib/raindrops/linux.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # For reporting TCP ListenStats, users of older \Linux kernels need to ensure # that the the "inet_diag" and "tcp_diag" kernel modules are loaded as they do diff --git a/lib/raindrops/middleware.rb b/lib/raindrops/middleware.rb index d5e3927..25b5a1e 100644 --- a/lib/raindrops/middleware.rb +++ b/lib/raindrops/middleware.rb @@ -1,5 +1,7 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'raindrops' +require 'thread' # Raindrops::Middleware is Rack middleware that allows snapshotting # current activity from an HTTP request. For all operating systems, @@ -93,11 +95,12 @@ class Raindrops::Middleware @app = app @stats = opts[:stats] || Stats.new @path = opts[:path] || "/_raindrops" + @mtx = Mutex.new tmp = opts[:listeners] if tmp.nil? && defined?(Unicorn) && Unicorn.respond_to?(:listener_names) tmp = Unicorn.listener_names end - @tcp = @unix = nil + @nl_sock = @tcp = @unix = nil if tmp @tcp = tmp.grep(/\A.+:\d+\z/) @@ -129,9 +132,12 @@ class Raindrops::Middleware "writing: #{@stats.writing}\n" if defined?(Raindrops::Linux.tcp_listener_stats) - Raindrops::Linux.tcp_listener_stats(@tcp).each do |addr,stats| - body << "#{addr} active: #{stats.active}\n" \ - "#{addr} queued: #{stats.queued}\n" + @mtx.synchronize do + @nl_sock ||= Raindrops::InetDiagSocket.new + Raindrops::Linux.tcp_listener_stats(@tcp, @nl_sock).each do |addr,stats| + body << "#{addr} active: #{stats.active}\n" \ + "#{addr} queued: #{stats.queued}\n" + end end if @tcp Raindrops::Linux.unix_listener_stats(@unix).each do |addr,stats| body << "#{addr} active: #{stats.active}\n" \ diff --git a/lib/raindrops/middleware/proxy.rb b/lib/raindrops/middleware/proxy.rb index a7c8e66..433950c 100644 --- a/lib/raindrops/middleware/proxy.rb +++ b/lib/raindrops/middleware/proxy.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # :stopdoc: # This class is used by Raindrops::Middleware to proxy application # response bodies. There should be no need to use it directly. diff --git a/lib/raindrops/struct.rb b/lib/raindrops/struct.rb index e81a78e..7233ce8 100644 --- a/lib/raindrops/struct.rb +++ b/lib/raindrops/struct.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # This is a wrapper around Raindrops objects much like the core Ruby # \Struct can be seen as a wrapper around the core \Array class. diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb index ac5b895..8fc0772 100644 --- a/lib/raindrops/watcher.rb +++ b/lib/raindrops/watcher.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "thread" require "time" require "socket" |