Class: Kafka::Datadog::ProducerSubscriber

Inherits:
StatsdSubscriber
  • Object
show all
Defined in:
lib/kafka/datadog.rb

Instance Method Summary collapse

Instance Method Details

#ack_message(event) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/kafka/datadog.rb', line 331

def ack_message(event)
  tags = {
    client: event.payload.fetch(:client_id),
    topic: event.payload.fetch(:topic),
  }

  # Number of messages ACK'd for the topic.
  increment("producer.ack.messages", tags: tags)

  # Histogram of delay between a message being produced and it being ACK'd.
  histogram("producer.ack.delay", event.payload.fetch(:delay), tags: tags)
end

#buffer_overflow(event) ⇒ Object



300
301
302
303
304
305
306
307
# File 'lib/kafka/datadog.rb', line 300

def buffer_overflow(event)
  tags = {
    client: event.payload.fetch(:client_id),
    topic: event.payload.fetch(:topic),
  }

  increment("producer.produce.errors", tags: tags)
end

#deliver_messages(event) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/kafka/datadog.rb', line 309

def deliver_messages(event)
  client = event.payload.fetch(:client_id)
  message_count = event.payload.fetch(:delivered_message_count)
  attempts = event.payload.fetch(:attempts)

  tags = {
    client: client,
  }

  if event.payload.key?(:exception)
    increment("producer.deliver.errors", tags: tags)
  end

  timing("producer.deliver.latency", event.duration, tags: tags)

  # Messages delivered to Kafka:
  count("producer.deliver.messages", message_count, tags: tags)

  # Number of attempts to deliver messages:
  histogram("producer.deliver.attempts", attempts, tags: tags)
end

#produce_message(event) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/kafka/datadog.rb', line 269

def produce_message(event)
  client = event.payload.fetch(:client_id)
  topic = event.payload.fetch(:topic)
  message_size = event.payload.fetch(:message_size)
  buffer_size = event.payload.fetch(:buffer_size)
  max_buffer_size = event.payload.fetch(:max_buffer_size)
  buffer_fill_ratio = buffer_size.to_f / max_buffer_size.to_f
  buffer_fill_percentage = buffer_fill_ratio * 100.0

  tags = {
    client: client,
    topic: topic,
  }

  # This gets us the write rate.
  increment("producer.produce.messages", tags: tags.merge(topic: topic))

  # Information about typical/average/95p message size.
  histogram("producer.produce.message_size", message_size, tags: tags.merge(topic: topic))

  # Aggregate message size.
  count("producer.produce.message_size.sum", message_size, tags: tags.merge(topic: topic))

  # This gets us the avg/max buffer size per producer.
  histogram("producer.buffer.size", buffer_size, tags: tags)

  # This gets us the avg/max buffer fill ratio per producer.
  histogram("producer.buffer.fill_ratio", buffer_fill_ratio, tags: tags)
  histogram("producer.buffer.fill_percentage", buffer_fill_percentage, tags: tags)
end

#topic_error(event) ⇒ Object



344
345
346
347
348
349
350
351
# File 'lib/kafka/datadog.rb', line 344

def topic_error(event)
  tags = {
    client: event.payload.fetch(:client_id),
    topic: event.payload.fetch(:topic)
  }

  increment("producer.ack.errors", tags: tags)
end