Java Code Examples for io.micrometer.core.instrument.MeterRegistry#forEachMeter()

The following examples show how to use io.micrometer.core.instrument.MeterRegistry#forEachMeter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryInspector.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
public static List<Datapoint> listDatapoints(String regName, Predicate<Meter> predicate) {
  List<Datapoint> result = new ArrayList<>();
  MeterRegistry registry = BackendRegistries.getNow(regName);
  if (registry == null) {
    throw new NoRegistryException(regName);
  }
  registry.forEachMeter(m -> {
    if (predicate.test(m)) {
      String id = id(m);
      m.measure().forEach(measurement -> {
        result.add(new Datapoint(id + "$" + measurement.getStatistic().name(), measurement.getValue()));
      });
    }
  });
  return result;
}
 
Example 2
Source File: CounterTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("function-tracking counter increments by change in a monotonically increasing function when observed")
default void functionTrackingCounter(MeterRegistry registry) {
    AtomicLong n = new AtomicLong(0);
    registry.more().counter("tracking", emptyList(), n);
    n.incrementAndGet();

    clock(registry).add(step());
    registry.forEachMeter(Meter::measure);
    assertThat(registry.get("tracking").functionCounter().count()).isEqualTo(1.0);
}
 
Example 3
Source File: OperatorMetricsTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Created new MetricsProvider and makes sure it doesn't contain any metrics from previous tests.
 *
 * @return  Clean MetricsProvider
 */
public MetricsProvider createCleanMetricsProvider() {
    MetricsProvider metrics = new MicrometerMetricsProvider();
    MeterRegistry registry = metrics.meterRegistry();

    registry.forEachMeter(meter -> {
        registry.remove(meter);
    });

    return metrics;
}
 
Example 4
Source File: TopicOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Created new MetricsProvider and makes sure it doesn't contain any metrics from previous tests.
 *
 * @return  Clean MetricsProvider
 */
public MetricsProvider createCleanMetricsProvider() {
    MetricsProvider metrics = new MicrometerMetricsProvider();
    MeterRegistry registry = metrics.meterRegistry();

    registry.forEachMeter(meter -> {
        registry.remove(meter);
    });

    return metrics;
}
 
Example 5
Source File: MoreMeters.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a newly-created immutable {@link Map} which contains all values of {@link Meter}s in the
 * specified {@link MeterRegistry}. The format of the key string is:
 * <ul>
 *   <li>{@code <name>#<statistic>{tagName=tagValue,...}}</li>
 *   <li>e.g. {@code "armeria.server.active.requests#value{method=greet}"}</li>
 *   <li>e.g. {@code "some.subsystem.some.value#count"} (no tags)</li>
 * </ul>
 * Note: It is not recommended to use this method for the purposes other than testing.
 */
public static Map<String, Double> measureAll(MeterRegistry registry) {
    requireNonNull(registry, "registry");

    final ImmutableMap.Builder<String, Double> builder = ImmutableMap.builder();

    registry.forEachMeter(meter -> Streams.stream(meter.measure()).forEach(measurement -> {
        final String fullName = measurementName(meter.getId(), measurement);
        final double value = measurement.getValue();
        builder.put(fullName, value);
    }));

    return builder.build();
}