Skip to content

Commit

Permalink
Update DropwizardExports.java
Browse files Browse the repository at this point in the history
Signed-off-by: Kinshuk Bairagi <[email protected]>
  • Loading branch information
kingster committed Dec 11, 2024
1 parent 4ec55f6 commit bb5ff35
Showing 1 changed file with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ MetricSnapshot fromCounter(String dropwizardName, Counter counter) {
/**
* Export gauge as a prometheus gauge.
*/
MetricSnapshot fromGauge(String dropwizardName, Gauge gauge) {
MetricSnapshot fromGauge(String dropwizardName, Gauge<?> gauge) {
Object obj = gauge.getValue();
double value;
if (obj instanceof Number) {
Expand Down Expand Up @@ -151,21 +151,26 @@ MetricSnapshot fromMeter(String dropwizardName, Meter meter) {
public MetricSnapshots collect() {
MetricSnapshots.Builder metricSnapshots = MetricSnapshots.builder();

for (SortedMap.Entry<String, Gauge> entry : registry.getGauges(metricFilter).entrySet()) {
Optional.ofNullable(fromGauge(entry.getKey(), entry.getValue())).map(metricSnapshots::metricSnapshot);
}
for (SortedMap.Entry<String, Counter> entry : registry.getCounters(metricFilter).entrySet()) {
metricSnapshots.metricSnapshot(fromCounter(entry.getKey(), entry.getValue()));
}
for (SortedMap.Entry<String, Histogram> entry : registry.getHistograms(metricFilter).entrySet()) {
metricSnapshots.metricSnapshot(fromHistogram(entry.getKey(), entry.getValue()));
}
for (SortedMap.Entry<String, Timer> entry : registry.getTimers(metricFilter).entrySet()) {
metricSnapshots.metricSnapshot(fromTimer(entry.getKey(), entry.getValue()));
}
for (SortedMap.Entry<String, Meter> entry : registry.getMeters(metricFilter).entrySet()) {
metricSnapshots.metricSnapshot(fromMeter(entry.getKey(), entry.getValue()));
}
registry.getGauges(metricFilter).forEach((name, gauge) -> {
MetricSnapshot snapshot = fromGauge(name, gauge);
if (snapshot != null) {
metricSnapshots.metricSnapshot(snapshot);
}
});

registry.getCounters(metricFilter).forEach((name, counter) ->
metricSnapshots.metricSnapshot(fromCounter(name, counter))
);
registry.getHistograms(metricFilter).forEach((name, histogram) ->
metricSnapshots.metricSnapshot(fromHistogram(name, histogram))
);
registry.getTimers(metricFilter).forEach((name, timer) ->
metricSnapshots.metricSnapshot(fromTimer(name, timer))
);
registry.getMeters(metricFilter).forEach((name, meter) ->
metricSnapshots.metricSnapshot(fromMeter(name, meter))
);

return metricSnapshots.build();
}

Expand Down

0 comments on commit bb5ff35

Please sign in to comment.