1.0.0
Metricize Kafka Client:
Metrics added to any consumer/producer/admin instance from this client
(object)
instance of KafkaJS Client
object
: metricized instance of KafkaJS Client
metricize(client);
Client Metrics Object:
Includes most recently calculated client metrics on KafkaJS client
Type: object
const clientMetricsObject = client.metrics;
Number of total consumers
Type: string
console.log(client.metrics.totalConsumers);
// => prints to the console: 25
Consumer/Producer/Admin Metrics Object:
Includes most recently calculated metrics and methods for consumer/producer/admin instances
Type: object
const consumerMetricsObject = consumer.metrics;
const producerMetricsObject = producer.metrics;
const adminMetricsObject = admin.metrics;
Optional name for consumer/producer/admin, set by user
Type: string
consumer.metrics.name = 'consumer_1'
Boolean value to indicate if consumer/producer/admin is connected
Type: boolean
console.log(producer.metrics.isConnected);
// => prints to the console: false
Timestamp value (ms) indicating initial consumer/producer/admin connection
Type: number
console.log(consumer.metrics.initialConnectionTimestamp);
// => prints to the console: 3957103428176
Timestamp value (ms) to indicating most recent consumer/producer/admin connection
Type: number
console.log(admin.metrics.currentConnectionTimestamp);
// => prints to the console: 3957103429678
Total number of requests
Type: number
console.log(producer.metrics.totalRequests);
// => prints to the console: 78
Total number of request timeouts
Type: number
console.log(consumer.metrics.totalRequestTimeouts);
// => prints to the console: 6
Request rate per specified metrics.options.rate.period value (default is 5000 ms)
Type: number
console.log(consumer.metrics.requestRate);
// => prints to the console: 78
Request rate over consumer/producer/admin lifetime (calculated since initial connection)
Type: number
console.log(consumer.metrics.requestRateLifetime);
// => prints to the console: 43
Timeout rate per specified metrics.options.rate.period value (default is 5000 ms)
Type: number
console.log(producer.metrics.timeoutRate);
// => prints to the console: 2
Timeout rate over consumer/producer/admin lifetime (calculated since initial connection)
Type: number
console.log(admin.metrics.timeoutRateLifetime);
// => prints to the console: 4
Turns on logging pendingDuration for every request (off by default)
consumer.metrics.requestPendingDurationLogOn()
// => prints log to the console; includes event payload apiName, pendingDuration
Turns off logging pendingDuration for every request
producer.metrics.requestPendingDurationLogOff()
Creates request pendingDuration breakpoint at specified interval (ms)
(number)
breakpoint in milliseconds
producer.metrics.requestPendingDurationSetBreakpoint(20)
// => prints log to the console when breakpoint is exceeded;
//includes event payload apiName, pendingDuration, ms breakpoint exceeded, current breakpoint
Cancels existing request pendingDuration breakpoint
producer.metrics.requestPendingDurationCancelBreakpoint()
Turns on logging requestQueueSize for every request (off by default)
consumer.metrics.requestQueueSizeLogOn()
// => prints log to the console; includes event payload queueSize
Turns off logging requestQueueSize for every request
consumer.metrics.requestQueueSizeLogOff()
Creates request queueSize breakpoint at specified size
(number)
breakpoint (queueSize number)
producer.metrics.requestQueueSizeSetBreakpoint(3)
// => prints log to the console when breakpoint is exceeded;
// includes event payload queueSize, amount breakpoint exceeded, current breakpoint
Cancels existing request queueSize breakpoint
producer.metrics.requestQueueSizeCancelBreakpoint()
Additional metrics for consumer instances
Type: object
const consumerMetrics = consumer.metrics;
memberId unique to each consumer; reassigned on every connection
Type: string
console.log(consumer.metrics.memberId);
// => prints to the console: your-app-5628039-8524-940e-b739-037aefda3e90
Number of total partitions subscribed to by consumer
Type: number
console.log(consumer.metrics.totalPartitions);
// => prints to the console: 3
Last consumer heartbeat timestamp (ms)
Type: number
console.log(consumer.metrics.lastHeartbeat);
// => prints to the console: 3957103428176
Last heartbeat duration in ms (time between last heartbeat and current heartbeat)
Type: number
console.log(consumer.metrics.lastHeartbeatDuration);
// => prints to the console: 4987
Longest heartbeat duration in ms since last consumer connection
Type: number
console.log(consumer.metrics.longestHeartbeatDuration);
// => prints to the console: 5987
Total number of messages consumed since last consumer connection
Type: number
console.log(consumer.metrics.messagesConsumed);
// => prints to the console: 487
Most recent end batch process offsetLag
Type: number
console.log(consumer.metrics.offsetLag);
// => prints to the console: 3
Message consumption rate per specified metrics.options.rate.period value (default: 5000 ms)
Type: number
console.log(consumer.metrics.messageConsumptionRate);
// => prints to the console: 78
Message consumption rate over consumer lifetime (calculated since initial connection)
Type: number
console.log(consumer.metrics.messageConsumptionRateLifetime);
// => prints to the console: 45
Turns on logging every heartbeat (off by default)
consumer.metrics.heartbeatLogOn()
// => prints log to the console; includes heartbeat event timestamp
Turns off logging every heartbeat
consumer.metrics.heartbeatLogOff()
Creates heartbeat breakpoint at specified interval (ms)
(number)
breakpoint in milliseconds
consumer.metrics.heartbeatSetBreakpoint(1000)
// => prints log to the console when breakpoint is exceeded;
// includes ms breakpoint exceeded, heartbeat event payload timestamp, current breakpoint
Cancels existing heartbeat breakpoint
consumer.metrics.heartbeatCancelBreakpoint()
Creates offsetLag breakpoint at specified integer
(number)
breakpoint number
consumer.metrics.offsetLagSetBreakpoint(4)
// => prints log to the console when breakpoint is exceeded;
// includes event payload offsetLag, amount breakpoint exceeded, current breakpoint
Cancels existing offsetLag breakpoint
consumer.metrics.offsetLagCancelBreakpoint()