Class: Consul::Async::EndPointStats

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeEndPointStats

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_bytesObject (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

#changesObject (readonly)

Returns the value of attribute changes.



8
9
10
# File 'lib/consul/async/stats.rb', line 8

def changes
  @changes
end

#consecutive_errorsObject (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

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/consul/async/stats.rb', line 8

def errors
  @errors
end

#last_errorObject (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_modifiedObject (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_successObject (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_bytesObject (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

#startObject (readonly)

Returns the value of attribute start.



8
9
10
# File 'lib/consul/async/stats.rb', line 8

def start
  @start
end

#successesObject (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_humanObject



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_errorObject



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