Java Code Examples for io.vertx.micrometer.backends.BackendRegistries#getNow()

The following examples show how to use io.vertx.micrometer.backends.BackendRegistries#getNow() . 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: PrometheusScrapingHandlerImpl.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext rc) {
  MeterRegistry registry;
  if (registryName == null) {
    registry = BackendRegistries.getDefaultNow();
  } else {
    registry = BackendRegistries.getNow(registryName);
  }
  if (registry instanceof PrometheusMeterRegistry) {
    PrometheusMeterRegistry prometheusMeterRegistry = (PrometheusMeterRegistry) registry;
    rc.response()
      .putHeader(HttpHeaders.CONTENT_TYPE, TextFormat.CONTENT_TYPE_004)
      .end(prometheusMeterRegistry.scrape());
  } else {
    String statusMessage = "Invalid registry: " + (registry != null ? registry.getClass().getName() : null);
    rc.response()
      .setStatusCode(500).setStatusMessage(statusMessage)
      .end();
  }
}
 
Example 2
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 3
Source File: MicrometerMetricsExamples.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
public void setupAndAccessCustomRegistry() {
  Vertx vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(
    new MicrometerMetricsOptions()
      .setInfluxDbOptions(new VertxInfluxDbOptions().setEnabled(true)) // or VertxPrometheusOptions
      .setRegistryName("my registry")
      .setEnabled(true)));

  // Later on:
  MeterRegistry registry = BackendRegistries.getNow("my registry");
}