Module: Mongo::Monitoring::Publishable

Overview

Defines behaviour for an object that can publish monitoring events.

Since:

  • 2.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#monitoringMonitoring (readonly)

Returns monitoring The monitoring.

Returns:

Since:

  • 2.1.0



24
25
26
# File 'lib/mongo/monitoring/publishable.rb', line 24

def monitoring
  @monitoring
end

Instance Method Details

#publish_command(messages, operation_id = Monitoring.next_operation_id) ⇒ Object

Publish a command event to the global monitoring.

Examples:

Publish a command event.

publish_command do |messages|
  # ...
end

Parameters:

  • messages (Array<Message>)

    The messages.

Returns:

  • (Object)

    The result of the yield.

Since:

  • 2.1.0



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mongo/monitoring/publishable.rb', line 38

def publish_command(messages, operation_id = Monitoring.next_operation_id)
  start = Time.now
  message = messages.first
  message.set_request_id
  payload = message.payload
  send_duration = duration(start)
  command_started(address, operation_id, payload)
  receive_start = Time.now
  begin
    result = yield(messages)
    total_duration = duration(receive_start) + send_duration
    command_completed(result, address, operation_id, payload, total_duration)
    result
  rescue Exception => e
    total_duration = duration(receive_start) + send_duration
    command_failed(address, operation_id, payload, e.message, total_duration)
    raise e
  end
end

#publish_event(topic, event) ⇒ Object

Since:

  • 2.1.0



58
59
60
# File 'lib/mongo/monitoring/publishable.rb', line 58

def publish_event(topic, event)
  monitoring.succeeded(topic, event)
end

#publish_sdam_event(topic, event) ⇒ Object

Since:

  • 2.1.0



62
63
64
# File 'lib/mongo/monitoring/publishable.rb', line 62

def publish_sdam_event(topic, event)
  monitoring.succeeded(topic, event) if monitoring?
end