Class: NATS::Service::Stats
- Inherits:
-
Object
- Object
- NATS::Service::Stats
- Includes:
- MonitorMixin
- Defined in:
- lib/nats/service/stats.rb
Instance Attribute Summary collapse
-
#average_processing_time ⇒ Object
readonly
Returns the value of attribute average_processing_time.
-
#last_error ⇒ Object
readonly
Returns the value of attribute last_error.
-
#num_errors ⇒ Object
readonly
Returns the value of attribute num_errors.
-
#num_requests ⇒ Object
readonly
Returns the value of attribute num_requests.
-
#processing_time ⇒ Object
readonly
Returns the value of attribute processing_time.
Instance Method Summary collapse
- #error(error) ⇒ Object
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #record(started_at) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Stats
Returns a new instance of Stats.
12 13 14 15 |
# File 'lib/nats/service/stats.rb', line 12 def initialize super reset end |
Instance Attribute Details
#average_processing_time ⇒ Object (readonly)
Returns the value of attribute average_processing_time.
10 11 12 |
# File 'lib/nats/service/stats.rb', line 10 def average_processing_time @average_processing_time end |
#last_error ⇒ Object (readonly)
Returns the value of attribute last_error.
10 11 12 |
# File 'lib/nats/service/stats.rb', line 10 def last_error @last_error end |
#num_errors ⇒ Object (readonly)
Returns the value of attribute num_errors.
10 11 12 |
# File 'lib/nats/service/stats.rb', line 10 def num_errors @num_errors end |
#num_requests ⇒ Object (readonly)
Returns the value of attribute num_requests.
10 11 12 |
# File 'lib/nats/service/stats.rb', line 10 def num_requests @num_requests end |
#processing_time ⇒ Object (readonly)
Returns the value of attribute processing_time.
10 11 12 |
# File 'lib/nats/service/stats.rb', line 10 def processing_time @processing_time end |
Instance Method Details
#error(error) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/nats/service/stats.rb', line 36 def error(error) error = ErrorWrapper.new(error) synchronize do @num_errors += 1 @last_error = error.description end end |
#record(started_at) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/nats/service/stats.rb', line 28 def record(started_at) synchronize do @num_requests += 1 @processing_time += to_nsec(Time.now - started_at) @average_processing_time = @processing_time / @num_requests end end |
#reset ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/nats/service/stats.rb', line 17 def reset synchronize do @num_requests = 0 @processing_time = 0 @average_processing_time = 0 @num_errors = 0 @last_error = "" end end |