Class: Consul::Async::EndPointStats
- Inherits:
-
Object
- Object
- Consul::Async::EndPointStats
- Defined in:
- lib/consul/async/stats.rb
Overview
Object keeping stats about a single Endpoint Accessible within the .stats of a EndPoint
Instance Attribute Summary collapse
-
#body_bytes ⇒ Object
readonly
Returns the value of attribute body_bytes.
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#consecutive_errors ⇒ Object
readonly
Returns the value of attribute consecutive_errors.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#last_error ⇒ Object
readonly
Returns the value of attribute last_error.
-
#last_modified ⇒ Object
readonly
Returns the value of attribute last_modified.
-
#last_success ⇒ Object
readonly
Returns the value of attribute last_success.
-
#network_bytes ⇒ Object
readonly
Returns the value of attribute network_bytes.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#successes ⇒ Object
readonly
Returns the value of attribute successes.
Instance Method Summary collapse
- #body_bytes_human ⇒ Object
- #bytes_per_sec(now = Time.now.utc) ⇒ Object
- #bytes_per_sec_human(now = Time.now.utc) ⇒ Object
-
#initialize ⇒ EndPointStats
constructor
A new instance of EndPointStats.
- #last_success_or_error ⇒ Object
- #on_error(_http) ⇒ Object
- #on_response(res) ⇒ Object
Constructor Details
#initialize ⇒ EndPointStats
Returns a new instance of EndPointStats.
10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#body_bytes ⇒ Object (readonly)
Returns the value of attribute body_bytes.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def body_bytes @body_bytes end |
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def changes @changes end |
#consecutive_errors ⇒ Object (readonly)
Returns the value of attribute consecutive_errors.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def consecutive_errors @consecutive_errors end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def errors @errors end |
#last_error ⇒ Object (readonly)
Returns the value of attribute last_error.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def last_error @last_error end |
#last_modified ⇒ Object (readonly)
Returns the value of attribute last_modified.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def last_modified @last_modified end |
#last_success ⇒ Object (readonly)
Returns the value of attribute last_success.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def last_success @last_success end |
#network_bytes ⇒ Object (readonly)
Returns the value of attribute network_bytes.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def network_bytes @network_bytes end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def start @start end |
#successes ⇒ Object (readonly)
Returns the value of attribute successes.
8 9 10 |
# File 'lib/consul/async/stats.rb', line 8 def successes @successes end |
Instance Method Details
#body_bytes_human ⇒ Object
49 50 51 |
# 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) ⇒ Object
39 40 41 42 43 |
# 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) ⇒ Object
45 46 47 |
# 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 ⇒ Object
53 54 55 |
# File 'lib/consul/async/stats.rb', line 53 def last_success_or_error [@last_error, @last_success].max end |
#on_error(_http) ⇒ Object
33 34 35 36 37 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# 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 |