class PumaCloudwatch::Metrics::Fetcher
Public Class Methods
new(options={})
click to toggle source
# File lib/puma_cloudwatch/metrics/fetcher.rb, line 6 def initialize(options={}) @control_url = options[:control_url] @control_auth_token = options[:control_auth_token] end
Public Instance Methods
call()
click to toggle source
# File lib/puma_cloudwatch/metrics/fetcher.rb, line 11 def call body = with_retries do read_socket end JSON.parse(body.split("\n").last) # stats end
Private Instance Methods
read_socket()
click to toggle source
# File lib/puma_cloudwatch/metrics/fetcher.rb, line 19 def read_socket Socket.unix(@control_url.gsub('unix://', '')) do |socket| socket.print("GET /stats?token=#{@control_auth_token} HTTP/1.0\r\n\r\n") socket.read end end
with_retries() { || ... }
click to toggle source
# File lib/puma_cloudwatch/metrics/fetcher.rb, line 26 def with_retries retries, max_attempts = 0, 10 yield rescue Errno::ENOENT => e retries += 1 if retries > max_attempts raise e end puts "retries #{retries} #{e.class} #{e.message}" if ENV['PUMA_CLOUDWATCH_SOCKET_RETRY'] sleep 1 retry end