lib/consul/async/stats.rb in consul-templaterb-1.5.5 vs lib/consul/async/stats.rb in consul-templaterb-1.5.6
- old
+ new
@@ -1,25 +1,29 @@
require 'consul/async/utilities'
module Consul
module Async
class EndPointStats
- attr_reader :successes, :errors, :start, :body_bytes
+ attr_reader :successes, :errors, :start, :body_bytes, :last_error, :last_success
def initialize
@start = Time.now.utc
@successes = 0
@errors = 0
@body_bytes = 0
+ @last_error = @start
+ @last_success = @start
end
def on_response(res)
+ @last_success = Time.now.utc
@successes += 1
@body_bytes = body_bytes + res.http.response.bytesize
end
def on_error(_http)
+ @last_error = Time.now.utc
@errors += 1
end
def bytes_per_sec
diff = (Time.now.utc - start)
@@ -31,9 +35,13 @@
"#{Utilities.bytes_to_h(bytes_per_sec)}/s"
end
def body_bytes_human
Utilities.bytes_to_h(body_bytes)
+ end
+
+ def last_success_or_error
+ [@last_error, @last_success].max
end
end
end
end