about summary refs log tree commit homepage
path: root/lib/raindrops/middleware.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/raindrops/middleware.rb')
-rw-r--r--lib/raindrops/middleware.rb18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/raindrops/middleware.rb b/lib/raindrops/middleware.rb
index ea7f08a..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,
@@ -62,9 +64,9 @@ require 'raindrops'
 # = Demo Server
 #
 # There is a server running this middleware (and Watcher) at
-#  https://raindrops-demo.bogomips.org/_raindrops
+#  https://yhbt.net/raindrops-demo/_raindrops
 #
-# Also check out the Watcher demo at https://raindrops-demo.bogomips.org/
+# Also check out the Watcher demo at https://yhbt.net/raindrops-demo/
 #
 # The demo server is only limited to 30 users, so be sure not to abuse it
 # by using the /tail/ endpoint too much.
@@ -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" \