diff --git a/src/main/java/io/strimzi/kafka/metrics/KafkaMetricsCollector.java b/src/main/java/io/strimzi/kafka/metrics/KafkaMetricsCollector.java index 32cbef6..50463b4 100644 --- a/src/main/java/io/strimzi/kafka/metrics/KafkaMetricsCollector.java +++ b/src/main/java/io/strimzi/kafka/metrics/KafkaMetricsCollector.java @@ -59,14 +59,14 @@ public List collect() { KafkaMetric kafkaMetric = entry.getValue(); LOG.trace("Collecting Kafka metric {}", metricName); - String name = metricName(metricName); + String prometheusMetricName = metricName(metricName); // TODO Filtering should take labels into account - if (!config.isAllowed(name)) { - LOG.info("Kafka metric {} is not allowed", name); + if (!config.isAllowed(prometheusMetricName)) { + LOG.info("Kafka metric {} is not allowed", prometheusMetricName); continue; } - LOG.info("Kafka metric {} is allowed", name); - MetricFamilySamples sample = convert(name, metricName.description(), kafkaMetric, metricName.tags(), metricName); + LOG.info("Kafka metric {} is allowed", prometheusMetricName); + MetricFamilySamples sample = convert(prometheusMetricName, kafkaMetric, metricName); if (sample != null) { samples.add(sample); } @@ -108,13 +108,13 @@ String metricName(MetricName metricName) { return prefix + '_' + group + '_' + name; } - static MetricFamilySamples convert(String name, String help, KafkaMetric metric, Map labels, MetricName metricName) { - Map sanitizedLabels = labels.entrySet().stream() + private static MetricFamilySamples convert(String prometheusMetricName, KafkaMetric metric, MetricName metricName) { + Map sanitizedLabels = metricName.tags().entrySet().stream() .collect(Collectors.toMap( e -> Collector.sanitizeMetricName(e.getKey()), Map.Entry::getValue, (v1, v2) -> { - LOG.warn("Unexpected duplicate key" + v1); + LOG.warn("Ignoring metric value duplicate key {}", v1); return v1; }, LinkedHashMap::new)); @@ -128,8 +128,8 @@ static MetricFamilySamples convert(String name, String help, KafkaMetric metric, sanitizedLabels.put(attributeName, String.valueOf(valueObj)); } - return new MetricFamilySamplesBuilder(Type.GAUGE, help) - .addSample(name, value, sanitizedLabels) + return new MetricFamilySamplesBuilder(Type.GAUGE, metric.metricName().description()) + .addSample(prometheusMetricName, value, sanitizedLabels) .build(); } } diff --git a/src/main/java/io/strimzi/kafka/metrics/YammerMetricsCollector.java b/src/main/java/io/strimzi/kafka/metrics/YammerMetricsCollector.java index 4210735..78b6d36 100644 --- a/src/main/java/io/strimzi/kafka/metrics/YammerMetricsCollector.java +++ b/src/main/java/io/strimzi/kafka/metrics/YammerMetricsCollector.java @@ -59,27 +59,27 @@ public List collect() { Metric metric = entry.getValue(); LOG.trace("Collecting Yammer metric {}", metricName); - String name = metricName(metricName); + String prometheusMetricName = metricName(metricName); // TODO Filtering should take labels into account - if (!config.isAllowed(name)) { - LOG.info("Yammer metric {} is not allowed", name); + if (!config.isAllowed(prometheusMetricName)) { + LOG.info("Yammer metric {} is not allowed", prometheusMetricName); continue; } - LOG.info("Yammer metric {} is allowed", name); + LOG.info("Yammer metric {} is allowed", prometheusMetricName); Map labels = labelsFromScope(metricName.getScope()); LOG.info("labels " + labels); MetricFamilySamples sample = null; if (metric instanceof Counter) { - sample = convert(name, (Counter) metric, labels); + sample = convert(prometheusMetricName, (Counter) metric, labels); } else if (metric instanceof Gauge) { - sample = convert(name, (Gauge) metric, labels, metricName); + sample = convert(prometheusMetricName, (Gauge) metric, labels, metricName); } else if (metric instanceof Histogram) { - sample = convert(name, (Histogram) metric, labels); + sample = convert(prometheusMetricName, (Histogram) metric, labels); } else if (metric instanceof Meter) { - sample = convert(name, (Meter) metric, labels); + sample = convert(prometheusMetricName, (Meter) metric, labels); } else if (metric instanceof Timer) { - sample = convert(name, (Timer) metric, labels); + sample = convert(prometheusMetricName, (Timer) metric, labels); } else { LOG.error("The metric " + metric.getClass().getName() + " has an unexpected type."); } @@ -115,19 +115,19 @@ static Map labelsFromScope(String scope) { return Collections.emptyMap(); } - static MetricFamilySamples convert(String name, Counter counter, Map labels) { + static MetricFamilySamples convert(String prometheusMetricName, Counter counter, Map labels) { return new MetricFamilySamplesBuilder(Type.GAUGE, "") - .addSample(name + "_count", counter.count(), labels) + .addSample(prometheusMetricName + "_count", counter.count(), labels) .build(); } - static MetricFamilySamples convert(String name, Gauge gauge, Map labels, MetricName metricName) { + private static MetricFamilySamples convert(String prometheusMetricName, Gauge gauge, Map labels, MetricName metricName) { Map sanitizedLabels = labels.entrySet().stream() .collect(Collectors.toMap( e -> Collector.sanitizeMetricName(e.getKey()), Map.Entry::getValue, (v1, v2) -> { - LOG.warn("Unexpected duplicate key " + v1); + LOG.warn("Ignoring metric value duplicate key {}", v1); return v1; }, LinkedHashMap::new)); @@ -142,27 +142,27 @@ static MetricFamilySamples convert(String name, Gauge gauge, Map labels) { + static MetricFamilySamples convert(String prometheusMetricName, Meter meter, Map labels) { return new MetricFamilySamplesBuilder(Type.COUNTER, "") - .addSample(name + "_count", meter.count(), labels) + .addSample(prometheusMetricName + "_count", meter.count(), labels) .build(); } - static MetricFamilySamples convert(String name, Histogram histogram, Map labels) { + static MetricFamilySamples convert(String prometheusMetricName, Histogram histogram, Map labels) { return new MetricFamilySamplesBuilder(Type.SUMMARY, "") - .addSample(name + "_count", histogram.count(), labels) - .addQuantileSamples(name, histogram.getSnapshot(), labels) + .addSample(prometheusMetricName + "_count", histogram.count(), labels) + .addQuantileSamples(prometheusMetricName, histogram.getSnapshot(), labels) .build(); } - static MetricFamilySamples convert(String name, Timer metric, Map labels) { + static MetricFamilySamples convert(String prometheusMetricName, Timer metric, Map labels) { return new MetricFamilySamplesBuilder(Type.SUMMARY, "") - .addSample(name + "_count", metric.count(), labels) - .addQuantileSamples(name, metric.getSnapshot(), labels) + .addSample(prometheusMetricName + "_count", metric.count(), labels) + .addQuantileSamples(prometheusMetricName, metric.getSnapshot(), labels) .build(); } }