Class: NATS::Service::Monitoring

Inherits:
Object
  • Object
show all
Defined in:
lib/nats/service/monitoring.rb

Constant Summary collapse

DEFAULT_PREFIX =
"$SRV"
VERBS =
{
  ping: "PING",
  info: "INFO",
  stats: "STATS"
}.freeze
TYPES =
{
  ping: "io.nats.micro.v1.ping_response",
  info: "io.nats.micro.v1.info_response",
  stats: "io.nats.micro.v1.stats_response"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, prefix = nil) ⇒ Monitoring

Returns a new instance of Monitoring.



24
25
26
27
28
29
# File 'lib/nats/service/monitoring.rb', line 24

def initialize(service, prefix = nil)
  @service = service
  @prefix = prefix || DEFAULT_PREFIX

  setup_monitors
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



22
23
24
# File 'lib/nats/service/monitoring.rb', line 22

def prefix
  @prefix
end

#serviceObject (readonly)

Returns the value of attribute service.



22
23
24
# File 'lib/nats/service/monitoring.rb', line 22

def service
  @service
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



22
23
24
# File 'lib/nats/service/monitoring.rb', line 22

def stopped
  @stopped
end

Instance Method Details

#stopObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nats/service/monitoring.rb', line 31

def stop
  return if @monitors.nil?

  @monitors.each do |monitor|
    service.client.send(:drain_sub, monitor)
  end
rescue
  # nothing we can do here
ensure
  @monitors = nil
end

#stopped?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/nats/service/monitoring.rb', line 43

def stopped?
  @monitors.nil?
end