Skip to content

Commit

Permalink
Merge pull request #5 from mazzy89/support-tcp
Browse files Browse the repository at this point in the history
Support TCP socket
  • Loading branch information
dsalahutdinov authored Dec 12, 2019
2 parents 87c84c7 + 5346fd4 commit 17489b6
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 17489b6

Please sign in to comment.