diff --git a/CHANGELOG.md b/CHANGELOG.md index 77c5a04b..cf8165ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.30.0 + +* Dependency updates (Prometheus JMX Collector 1.0.1, Prometheus Client 1.3.1) + ## 0.29.0 * Dependency updates (Vert.x 4.5.8, Netty 4.1.110.Final) diff --git a/pom.xml b/pom.xml index e02dfac0..b030ae86 100644 --- a/pom.xml +++ b/pom.xml @@ -133,8 +133,8 @@ 1.21.0-alpha 1.61.0 1.12.3 - 0.18.0 - 0.16.0 + 1.0.1 + 1.3.1 1.4 0.106.0 2.3.2 @@ -292,13 +292,13 @@ io.prometheus - simpleclient - ${prometheus-simpleclient.version} + prometheus-metrics-model + ${prometheus-client.version} io.prometheus - simpleclient_common - ${prometheus-simpleclient.version} + prometheus-metrics-exposition-formats + ${prometheus-client.version} commons-cli @@ -493,6 +493,7 @@ false + posix src/main/assembly/assembly.xml diff --git a/src/main/java/io/strimzi/kafka/bridge/JmxCollectorRegistry.java b/src/main/java/io/strimzi/kafka/bridge/JmxCollectorRegistry.java index 2df4a7f3..27107d3d 100644 --- a/src/main/java/io/strimzi/kafka/bridge/JmxCollectorRegistry.java +++ b/src/main/java/io/strimzi/kafka/bridge/JmxCollectorRegistry.java @@ -5,22 +5,22 @@ package io.strimzi.kafka.bridge; -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.exporter.common.TextFormat; import io.prometheus.jmx.JmxCollector; +import io.prometheus.metrics.expositionformats.PrometheusTextFormatWriter; +import io.prometheus.metrics.model.registry.PrometheusRegistry; import javax.management.MalformedObjectNameException; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; +import java.nio.charset.StandardCharsets; /** * Allow to collect JMX metrics exposing them in the Prometheus format */ public class JmxCollectorRegistry { - - private final CollectorRegistry collectorRegistry; + private final PrometheusRegistry collectorRegistry; + private final PrometheusTextFormatWriter textFormatter = new PrometheusTextFormatWriter(true); /** * Constructor @@ -30,7 +30,7 @@ public class JmxCollectorRegistry { */ public JmxCollectorRegistry(String yamlConfig) throws MalformedObjectNameException { new JmxCollector(yamlConfig).register(); - collectorRegistry = CollectorRegistry.defaultRegistry; + collectorRegistry = PrometheusRegistry.defaultRegistry; } /** @@ -42,7 +42,7 @@ public JmxCollectorRegistry(String yamlConfig) throws MalformedObjectNameExcepti */ public JmxCollectorRegistry(File yamlFileConfig) throws MalformedObjectNameException, IOException { new JmxCollector(yamlFileConfig).register(); - collectorRegistry = CollectorRegistry.defaultRegistry; + collectorRegistry = PrometheusRegistry.defaultRegistry; } /** @@ -50,12 +50,12 @@ public JmxCollectorRegistry(File yamlFileConfig) throws MalformedObjectNameExcep * Prometheus to scrape from. */ public String scrape() { - Writer writer = new StringWriter(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { - TextFormat.write004(writer, collectorRegistry.metricFamilySamples()); + textFormatter.write(stream, collectorRegistry.scrape()); } catch (IOException e) { throw new RuntimeException(e); } - return writer.toString(); + return stream.toString(StandardCharsets.UTF_8); } } diff --git a/src/main/resources/jmx_metrics_config.yaml b/src/main/resources/jmx_metrics_config.yaml index 25398ad7..68bd54da 100644 --- a/src/main/resources/jmx_metrics_config.yaml +++ b/src/main/resources/jmx_metrics_config.yaml @@ -2,6 +2,13 @@ lowercaseOutputName: true rules: # more specific rules to consumer and producer with topic related information + - pattern: kafka.producer<>([a-z-]+)-total + name: strimzi_bridge_kafka_producer_$4_total + type: COUNTER + labels: + type: "$1" + clientId: "$2" + topic: "$3" - pattern: kafka.producer<>([a-z-]+) name: strimzi_bridge_kafka_producer_$4 type: GAUGE @@ -9,6 +16,13 @@ rules: type: "$1" clientId: "$2" topic: "$3" + - pattern: kafka.consumer<>([a-z-]+)-total + name: strimzi_bridge_kafka_consumer_$4_total + type: COUNTER + labels: + type: "$1" + clientId: "$2" + topic: "$3" - pattern: kafka.consumer<>([a-z-]+) name: strimzi_bridge_kafka_consumer_$4 type: GAUGE @@ -17,6 +31,18 @@ rules: clientId: "$2" topic: "$3" # more general metrics + - pattern: kafka.(\w+)<>([a-z-]+-total-[a-z-]+) # handles the metrics with total in the middle of the metric name + name: strimzi_bridge_kafka_$1_$4 + type: GAUGE + labels: + type: "$2" + clientId: "$3" + - pattern: kafka.(\w+)<>([a-z-]+)-total + name: strimzi_bridge_kafka_$1_$4_total + type: COUNTER + labels: + type: "$2" + clientId: "$3" - pattern: kafka.(\w+)<>([a-z-]+) name: strimzi_bridge_kafka_$1_$4 type: GAUGE