Skip to content

Commit bb5ff35

Browse files
committed
Update DropwizardExports.java
Signed-off-by: Kinshuk Bairagi <[email protected]>
1 parent 4ec55f6 commit bb5ff35

File tree

1 file changed

+21
-16
lines changed
  • prometheus-metrics-instrumentation-dropwizard/src/main/java/io/prometheus/metrics/instrumentation/dropwizard

1 file changed

+21
-16
lines changed

prometheus-metrics-instrumentation-dropwizard/src/main/java/io/prometheus/metrics/instrumentation/dropwizard/DropwizardExports.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ MetricSnapshot fromCounter(String dropwizardName, Counter counter) {
7979
/**
8080
* Export gauge as a prometheus gauge.
8181
*/
82-
MetricSnapshot fromGauge(String dropwizardName, Gauge gauge) {
82+
MetricSnapshot fromGauge(String dropwizardName, Gauge<?> gauge) {
8383
Object obj = gauge.getValue();
8484
double value;
8585
if (obj instanceof Number) {
@@ -151,21 +151,26 @@ MetricSnapshot fromMeter(String dropwizardName, Meter meter) {
151151
public MetricSnapshots collect() {
152152
MetricSnapshots.Builder metricSnapshots = MetricSnapshots.builder();
153153

154-
for (SortedMap.Entry<String, Gauge> entry : registry.getGauges(metricFilter).entrySet()) {
155-
Optional.ofNullable(fromGauge(entry.getKey(), entry.getValue())).map(metricSnapshots::metricSnapshot);
156-
}
157-
for (SortedMap.Entry<String, Counter> entry : registry.getCounters(metricFilter).entrySet()) {
158-
metricSnapshots.metricSnapshot(fromCounter(entry.getKey(), entry.getValue()));
159-
}
160-
for (SortedMap.Entry<String, Histogram> entry : registry.getHistograms(metricFilter).entrySet()) {
161-
metricSnapshots.metricSnapshot(fromHistogram(entry.getKey(), entry.getValue()));
162-
}
163-
for (SortedMap.Entry<String, Timer> entry : registry.getTimers(metricFilter).entrySet()) {
164-
metricSnapshots.metricSnapshot(fromTimer(entry.getKey(), entry.getValue()));
165-
}
166-
for (SortedMap.Entry<String, Meter> entry : registry.getMeters(metricFilter).entrySet()) {
167-
metricSnapshots.metricSnapshot(fromMeter(entry.getKey(), entry.getValue()));
168-
}
154+
registry.getGauges(metricFilter).forEach((name, gauge) -> {
155+
MetricSnapshot snapshot = fromGauge(name, gauge);
156+
if (snapshot != null) {
157+
metricSnapshots.metricSnapshot(snapshot);
158+
}
159+
});
160+
161+
registry.getCounters(metricFilter).forEach((name, counter) ->
162+
metricSnapshots.metricSnapshot(fromCounter(name, counter))
163+
);
164+
registry.getHistograms(metricFilter).forEach((name, histogram) ->
165+
metricSnapshots.metricSnapshot(fromHistogram(name, histogram))
166+
);
167+
registry.getTimers(metricFilter).forEach((name, timer) ->
168+
metricSnapshots.metricSnapshot(fromTimer(name, timer))
169+
);
170+
registry.getMeters(metricFilter).forEach((name, meter) ->
171+
metricSnapshots.metricSnapshot(fromMeter(name, meter))
172+
);
173+
169174
return metricSnapshots.build();
170175
}
171176

0 commit comments

Comments
 (0)