Kafka client collector is an implementation of Prometheus custom collector, for collecting JMX metrics from kafka clients.
Version | Kafka-client version | Prometheus simpleclient version |
---|---|---|
0.0.3 | 2.1.1 | 0.6.0 |
0.0.4 | 2.3.0 | 0.6.0 |
0.0.5 | 2.3.0 | 0.6.0 |
<dependency>
<groupId>no.sysco.middleware.prometheus</groupId>
<artifactId>kafka-client-collector</artifactId>
<version>0.0.5</version>
</dependency>
Use KafkaClientsJmxExports
to initialize collectors for kafka client's JMX metrics to conveniently register them.
HTTPServer server = new HTTPServer(8081);
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
KafkaClientsJmxExports.initialize(kafkaProducer1);
Add armeria dependency, than
/** init health-check, config, metrics */
final CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry;
new ClientsJmxCollector(kafkaProducer).register(collectorRegistry);
Server server = new ServerBuilder().http(8085)
.service("/", (ctx, req) -> HttpResponse.of("OK"))
.service("/config", (ctx, req) -> HttpResponse.of(appConfig.properties.toString()))
.service("/metrics", (ctx, req) -> {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
try (OutputStreamWriter writer = new OutputStreamWriter(stream)) {
TextFormat.write004(writer, collectorRegistry.metricFamilySamples());
}
return HttpResponse.of(HttpStatus.OK, CONTENT_TYPE_004, stream.toByteArray());
})
.build();
CompletableFuture<Void> future = server.start();
// Wait until the server is ready.
future.join();
Follow full example
JMX example
kafka.producer:type=producer-metrics,client-id="dasf-gdfgd-dfgd-31",waiting-threads="5"
Will be exposed as
producer_metrics_waiting_threads {cliend_id="dasf-gdfgd-dfgd-31"} 5.0
JMX domain (kafka.producer - example above) is not present in Prometheus format, due to kafka-streams api use others apis (kafka-producer, kafka-consumer, kafka-admin-client) and domain names are not presented in KafkaMetric.
app-info
@deprecatedproducer-metrics
producer-topic-metrics
producer-node-metrics
app-info
@deprecatedconsumer-metrics
consumer-coordinator-metrics
consumer-fetch-manager-metrics
consumer-node-metrics
Stream contains metrics from domains kafka.producer
, kafka.consumer
, kafka.admin.client
and own set of metrics
such as :
app-info
@deprecatedstream-metrics
[INFO lvl]stream-task-metrics
[DEBUG lvl]stream-processor-node-metrics
[DEBUG lvl]stream-[store-scope]-metrics
[DEBUG lvl]stream-record-cache-metrics
[DEBUG lvl]stream-buffer-metrics
[DEBUG lvl]
- Check
Read blog post.
There is a tool
promtool
to verify metrics formatting.
- More examples
- Issue 305: Add kafka client example config
- Issue 400: does the client automatically publish jmx mertices (heap size memory, thread number)?
- Blog post: JMX monitoring + Java custom metrics.
- Kafka metrics reporter
- IMO - Good example how to make custom collector
- Approaches (POCs) with
org.apache.kafka.common.metrics.MetricReporter
- Micrometer [PR WIP]