eu.xenit.alfred.telemetry.service.MeterRegistryService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alfred-telemetry-platform Show documentation
Show all versions of alfred-telemetry-platform Show documentation
Alfred Telemetry Platform module which enables exposure of Metrics using Micrometer
package eu.xenit.alfred.telemetry.service;
import eu.xenit.alfred.telemetry.util.MeterRegistryUtil;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
public class MeterRegistryService {
private final MeterRegistry meterRegistry;
public MeterRegistryService(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}
public Set getMeterNames() {
TreeSet names = new TreeSet<>();
this.collectNames(names, meterRegistry);
return names;
}
public Collection findFirstMatchingMeters(final String name, final Iterable tags) {
return MeterRegistryUtil.findFirstMatchingMeters(meterRegistry, name, tags);
}
/* PRIVATE METHODS */
private void collectNames(Set names, MeterRegistry registry) {
if (registry instanceof CompositeMeterRegistry) {
((CompositeMeterRegistry) registry).getRegistries().forEach((member) -> collectNames(names, member));
} else {
registry.getMeters().stream().map(this::getName).forEach(names::add);
}
}
private String getName(Meter meter) {
return meter.getId().getName();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy