class Consul::Async::EndPointStats
Object keeping stats about a single Endpoint Accessible within the .stats of a EndPoint
Attributes
body_bytes[R]
changes[R]
consecutive_errors[R]
errors[R]
last_error[R]
last_modified[R]
last_success[R]
network_bytes[R]
start[R]
successes[R]
Public Class Methods
new()
click to toggle source
# File lib/consul/async/stats.rb, line 10 def initialize @start = Time.now.utc @successes = 0 @errors = 0 @body_bytes = 0 @changes = 0 @network_bytes = 0 @last_error = @start @last_success = @start @last_modified = @start @consecutive_errors = 0 end
Public Instance Methods
body_bytes_human()
click to toggle source
# File lib/consul/async/stats.rb, line 49 def body_bytes_human Utilities.bytes_to_h(body_bytes) end
bytes_per_sec(now = Time.now.utc)
click to toggle source
# File lib/consul/async/stats.rb, line 39 def bytes_per_sec(now = Time.now.utc) diff = (now - start) diff = 1 if diff < 1 (body_bytes / diff).round(0) end
bytes_per_sec_human(now = Time.now.utc)
click to toggle source
# File lib/consul/async/stats.rb, line 45 def bytes_per_sec_human(now = Time.now.utc) "#{Utilities.bytes_to_h(bytes_per_sec(now))}/s" end
last_success_or_error()
click to toggle source
# File lib/consul/async/stats.rb, line 53 def last_success_or_error [@last_error, @last_success].max end
on_error(_http)
click to toggle source
# File lib/consul/async/stats.rb, line 33 def on_error(_http) @last_error = Time.now.utc @errors += 1 @consecutive_errors += 1 end
on_response(res)
click to toggle source
# File lib/consul/async/stats.rb, line 23 def on_response(res) @last_success = Time.now.utc @successes += 1 @body_bytes += res.http.response.bytesize @changes += 1 if res.modified? @last_modified = @last_success if res.modified? @consecutive_errors = 0 @network_bytes += res.http.response_header['Content-Length'].to_i end