Skip to content

Commit

Permalink
Support TCP socket
Browse files Browse the repository at this point in the history
Signed-off-by: Salvatore Mazzarino <[email protected]>
  • Loading branch information
mazzy89 committed Dec 12, 2019
1 parent 87c84c7 commit 5346fd4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/yabeda/puma/plugin/statistics/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ module Plugin
module Statistics
class Fetcher
def self.call
body = Socket.unix(Yabeda::Puma::Plugin.control_url.gsub("unix://", '')) do |socket|
control_url = Yabeda::Puma::Plugin.control_url

if control_url.start_with? "unix://"
path = control_url.gsub("unix://", '')
sock = Socket.unix(path)
elsif control_url.start_with? "tcp://"
host, port = control_url.match(/^tcp:\/\/([a-z0-9\-._~%]+):([0-9]+)/).captures

sock = Socket.tcp(host, port)
else
raise ArgumentError("Unknown puma control url type #{control_url}")
end

body = sock do |socket|
socket << "GET /stats?token=#{Yabeda::Puma::Plugin.control_auth_token} HTTP/1.0\r\n\r\n"
socket.read
end
Expand Down

0 comments on commit 5346fd4

Please sign in to comment.