Class: NATS::Service::Stats

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/nats/service/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

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_timeObject (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_errorObject (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_errorsObject (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_requestsObject (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_timeObject (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

#resetObject



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