io.vertx.micrometer.backends.BackendRegistries Java Examples

The following examples show how to use io.vertx.micrometer.backends.BackendRegistries. 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: GaugesTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreGaugeLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue(".*")
    .setAlias("_")));
  Gauges<LongAdder> gauges = new Gauges<>("my_gauge", "", LongAdder::new, LongAdder::doubleValue, registry, Label.EB_ADDRESS);
  gauges.get("addr1").increment();
  gauges.get("addr1").increment();
  gauges.get("addr2").increment();

  Gauge g = registry.find("my_gauge").tags("address", "_").gauge();
  assertThat(g.value()).isEqualTo(3d);
  g = registry.find("my_gauge").tags("address", "addr1").gauge();
  assertThat(g).isNull();
  g = registry.find("my_gauge").tags("address", "addr2").gauge();
  assertThat(g).isNull();
}
 
Example #2
Source File: MatchersTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFilterMetric() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, EnumSet.allOf(Label.class), Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.EQUALS)
    .setValue("addr1")));
  Counters counters = new Counters("my_counter", "", registry, Label.EB_ADDRESS);
  counters.get("addr1").increment();
  counters.get("addr2").increment();

  Counter c = registry.find("my_counter").tags("address", "addr1").counter();
  assertThat(c.count()).isEqualTo(1d);
  c = registry.find("my_counter").tags("address", "addr2").counter();
  assertThat(c).isNull();
}
 
Example #3
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 #4
Source File: CountersTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasCounterLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue("addr1")
    .setAlias("1")));
  Counters counters = new Counters("my_counter", "", registry, Label.EB_ADDRESS);
  counters.get("addr1").increment();
  counters.get("addr1").increment();
  counters.get("addr2").increment();

  Counter c = registry.find("my_counter").tags("address", "1").counter();
  assertThat(c.count()).isEqualTo(2d);
  c = registry.find("my_counter").tags("address", "addr1").counter();
  assertThat(c).isNull();
  c = registry.find("my_counter").tags("address", "addr2").counter();
  assertThat(c.count()).isEqualTo(1d);
}
 
Example #5
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 #6
Source File: CountersTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreCounterLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue(".*")
    .setAlias("_")));
  Counters counters = new Counters("my_counter", "", registry, Label.EB_ADDRESS);
  counters.get("addr1").increment();
  counters.get("addr1").increment();
  counters.get("addr2").increment();

  Counter c = registry.find("my_counter").tags("address", "_").counter();
  assertThat(c.count()).isEqualTo(3d);
  c = registry.find("my_counter").tags("address", "addr1").counter();
  assertThat(c).isNull();
  c = registry.find("my_counter").tags("address", "addr2").counter();
  assertThat(c).isNull();
}
 
Example #7
Source File: SummariesTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasSummaryLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue("addr1")
    .setAlias("1")));
  Summaries summaries = new Summaries("my_summary", "", registry, Label.EB_ADDRESS);
  summaries.get("addr1").record(5);
  summaries.get("addr1").record(8);
  summaries.get("addr2").record(10);

  DistributionSummary s = registry.find("my_summary").tags("address", "1").summary();
  assertThat(s.count()).isEqualTo(2);
  assertThat(s.totalAmount()).isEqualTo(13);
  s = registry.find("my_summary").tags("address", "addr1").summary();
  assertThat(s).isNull();
  s = registry.find("my_summary").tags("address", "addr2").summary();
  assertThat(s.count()).isEqualTo(1);
  assertThat(s.totalAmount()).isEqualTo(10);
}
 
Example #8
Source File: SummariesTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreSummaryLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue(".*")
    .setAlias("_")));
  Summaries summaries = new Summaries("my_summary", "", registry, Label.EB_ADDRESS);
  summaries.get("addr1").record(5);
  summaries.get("addr1").record(8);
  summaries.get("addr2").record(10);

  DistributionSummary s = registry.find("my_summary").tags("address", "_").summary();
  assertThat(s.count()).isEqualTo(3);
  assertThat(s.totalAmount()).isEqualTo(23);
  s = registry.find("my_summary").tags("address", "addr1").summary();
  assertThat(s).isNull();
  s = registry.find("my_summary").tags("address", "addr2").summary();
  assertThat(s).isNull();
}
 
Example #9
Source File: GaugesTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasGaugeLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue("addr1")
    .setAlias("1")));
  Gauges<LongAdder> gauges = new Gauges<>("my_gauge", "", LongAdder::new, LongAdder::doubleValue, registry, Label.EB_ADDRESS);
  gauges.get("addr1").increment();
  gauges.get("addr1").increment();
  gauges.get("addr2").increment();

  Gauge g = registry.find("my_gauge").tags("address", "1").gauge();
  assertThat(g.value()).isEqualTo(2d);
  g = registry.find("my_gauge").tags("address", "addr1").gauge();
  assertThat(g).isNull();
  g = registry.find("my_gauge").tags("address", "addr2").gauge();
  assertThat(g.value()).isEqualTo(1d);
}
 
Example #10
Source File: Ball.java    From demo-mesh-arena with Apache License 2.0 6 votes vote down vote up
private Ball(Vertx vertx) {
  client = WebClient.create(vertx);
  id = "ball-" + UUID.randomUUID().toString();
  json = new JsonObject()
      .put("id", id)
      .put("style", "position: absolute; background-image: url(./" + IMAGE + ".png); width: 20px; height: 20px;"
          + "z-index: 5; transition: top " + DELTA_MS + "ms, left " + DELTA_MS + "ms;")
      .put("text", "");

  registry = Optional.ofNullable(BackendRegistries.getDefaultNow());
  registry.ifPresent(reg -> Gauge.builder("mesharena_ball_speed", () -> speed.size())
      .description("Ball speed gauge")
      .register(reg));
  if (!registry.isPresent()) {
    System.out.println("No metrics");
  }
}
 
Example #11
Source File: TimersTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasTimerLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue("addr1")
    .setAlias("1")));
  Timers timers = new Timers("my_timer", "", registry, Label.EB_ADDRESS);
  timers.get("addr1").record(5, TimeUnit.MILLISECONDS);
  timers.get("addr1").record(8, TimeUnit.MILLISECONDS);
  timers.get("addr2").record(10, TimeUnit.MILLISECONDS);

  Timer t = registry.find("my_timer").tags("address", "1").timer();
  assertThat(t.count()).isEqualTo(2);
  assertThat(t.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(13);
  t = registry.find("my_timer").tags("address", "addr1").timer();
  assertThat(t).isNull();
  t = registry.find("my_timer").tags("address", "addr2").timer();
  assertThat(t.count()).isEqualTo(1);
  assertThat(t.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(10);
}
 
Example #12
Source File: TimersTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreTimerLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue(".*")
    .setAlias("_")));
  Timers timers = new Timers("my_timer", "", registry, Label.EB_ADDRESS);
  timers.get("addr1").record(5, TimeUnit.MILLISECONDS);
  timers.get("addr1").record(8, TimeUnit.MILLISECONDS);
  timers.get("addr2").record(10, TimeUnit.MILLISECONDS);

  Timer t = registry.find("my_timer").timer();
  assertThat(t.count()).isEqualTo(3);
  assertThat(t.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(23);
  t = registry.find("my_timer").tags("address", "addr1").timer();
  assertThat(t).isNull();
  t = registry.find("my_timer").tags("address", "addr2").timer();
  assertThat(t).isNull();
}
 
Example #13
Source File: PrometheusMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBindExistingServer(TestContext context) {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
      .setEnabled(true)));

  Router router = Router.router(vertx);
  router.route("/custom").handler(routingContext -> {
    PrometheusMeterRegistry prometheusRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
    String response = prometheusRegistry.scrape();
    routingContext.response().end(response);
  });
  vertx.createHttpServer().requestHandler(router).exceptionHandler(context.exceptionHandler()).listen(8081);

  Async async = context.async();
  PrometheusTestHelper.tryConnect(vertx, context, 8081, "localhost", "/custom", body -> {
    context.verify(v -> assertThat(body.toString())
          .contains("vertx_http_"));
    async.complete();
  });
  async.awaitSuccess(10000);
}
 
Example #14
Source File: AmqpBridgeServer.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        Vertx vertx = Vertx.vertx();

        Map<String, Object> config = new HashMap<>();
        BridgeConfig bridgeConfig = BridgeConfig.fromMap(config);
        MeterRegistry meterRegistry = BackendRegistries.getDefaultNow();
        
        AmqpBridge bridge = new AmqpBridge(bridgeConfig, new MetricsReporter(null, meterRegistry));

        vertx.deployVerticle(bridge);

        try {
            System.in.read();
            vertx.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
Example #15
Source File: MatchersTest.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFilterDomainMetric() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, EnumSet.allOf(Label.class), Collections.singletonList(new Match()
    .setLabel("address")
    .setDomain(MetricsDomain.EVENT_BUS)
    .setType(MatchType.EQUALS)
    .setValue("addr1")));
  String metric1 = MetricsDomain.EVENT_BUS.getPrefix() + "_counter";
  Counters counters1 = new Counters(metric1, "", registry, Label.EB_ADDRESS);
  counters1.get("addr1").increment();
  counters1.get("addr2").increment();
  String metric2 = "another_domain_counter";
  Counters counters2 = new Counters(metric2, "", registry, Label.EB_ADDRESS);
  counters2.get("addr1").increment();
  counters2.get("addr2").increment();

  // In domain where the rule applies, filter is performed
  Counter c = registry.find(metric1).tags("address", "addr1").counter();
  assertThat(c.count()).isEqualTo(1d);
  c = registry.find(metric1).tags("address", "addr2").counter();
  assertThat(c).isNull();
  // In other domain, no filter
  c = registry.find(metric2).tags("address", "addr1").counter();
  assertThat(c.count()).isEqualTo(1d);
  c = registry.find(metric2).tags("address", "addr2").counter();
  assertThat(c.count()).isEqualTo(1d);
}
 
Example #16
Source File: UserOperator.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public UserOperator(String namespace,
                    UserOperatorConfig config,
                    KubernetesClient client,
                    KafkaUserOperator kafkaUserOperator) {
    log.info("Creating UserOperator for namespace {}", namespace);
    this.namespace = namespace;
    this.reconciliationInterval = config.getReconciliationIntervalMs();
    this.client = client;
    this.kafkaUserOperator = kafkaUserOperator;
    this.metrics = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
}
 
Example #17
Source File: Session.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public Session(KubernetesClient kubeClient, Config config) {
    this.kubeClient = kubeClient;
    this.config = config;
    StringBuilder sb = new StringBuilder(System.lineSeparator());
    for (Config.Value<?> v: Config.keys()) {
        sb.append("\t").append(v.key).append(": ").append(Util.maskPassword(v.key, config.get(v).toString())).append(System.lineSeparator());
    }
    LOGGER.info("Using config:{}", sb.toString());
    this.metricsRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
}
 
Example #18
Source File: VertxNetClientServerMetricsTest.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext ctx) {
  vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
    .addDisabledMetricsCategory(MetricsDomain.EVENT_BUS)
    .addLabels(Label.LOCAL, Label.REMOTE)
    .setRegistryName(registryName)
    .setEnabled(true)))
    .exceptionHandler(ctx.exceptionHandler());

  // Filter out remote labels
  BackendRegistries.getNow(registryName).config().meterFilter(
    MeterFilter.replaceTagValues(Label.REMOTE.toString(), s -> "_", "localhost:9194"));

  // Setup server
  Async serverReady = ctx.async();
  vertx.deployVerticle(new AbstractVerticle() {
    @Override
    public void start(Promise<Void> future) throws Exception {
      netServer = vertx.createNetServer();
      netServer
        .connectHandler(socket -> socket.handler(buffer -> socket.write(SERVER_RESPONSE)))
        .listen(9194, "localhost", r -> {
          if (r.failed()) {
            ctx.fail(r.cause());
          } else {
            serverReady.complete();
          }
        });
    }
  });
  serverReady.awaitSuccess();
}
 
Example #19
Source File: DeployKonduitServing.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInference(DeploymentOptions deploymentOptions, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInference(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            deploymentOptions, eventHandler);
}
 
Example #20
Source File: DeployKonduitServing.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInference(InferenceConfiguration inferenceConfiguration, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInference(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            new DeploymentOptions().setConfig(new JsonObject(inferenceConfiguration.toJson())), eventHandler);
}
 
Example #21
Source File: MetricsUtils.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up promethues and returns the
 * registry
 * @return
 */
public static Pair<MicrometerMetricsOptions,MeterRegistry> setupPrometheus() {
    PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(registry)
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    return Pair.of(micrometerMetricsOptions,registry);

}
 
Example #22
Source File: DeployKonduitOrchestration.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInferenceClustered(DeploymentOptions deploymentOptions, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInferenceClustered(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            deploymentOptions, eventHandler);
}
 
Example #23
Source File: DeployKonduitOrchestration.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInferenceClustered(InferenceConfiguration inferenceConfiguration, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInferenceClustered(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            new DeploymentOptions().setConfig(new JsonObject(inferenceConfiguration.toJson())), eventHandler);
}
 
Example #24
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");
}
 
Example #25
Source File: MicrometerMetricsExamples.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
public void customTimerExample() {
  MeterRegistry registry = BackendRegistries.getDefaultNow();
  Timer timer = Timer
    .builder("my.timer")
    .description("a description of what this timer does")
    .register(registry);

  vertx.setPeriodic(1000, l -> {
    timer.record(() -> {
      // Running here some operation to monitor
    });
  });
}
 
Example #26
Source File: MicrometerMetricsExamples.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
public void instrumentJVM() {
  MeterRegistry registry = BackendRegistries.getDefaultNow();

  new ClassLoaderMetrics().bindTo(registry);
  new JvmMemoryMetrics().bindTo(registry);
  new JvmGcMetrics().bindTo(registry);
  new ProcessorMetrics().bindTo(registry);
  new JvmThreadMetrics().bindTo(registry);
}
 
Example #27
Source File: MicrometerMetricsExamples.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
public void useMicrometerFilters() {
  MeterRegistry registry = BackendRegistries.getDefaultNow();
  Pattern pattern = Pattern.compile("/foo/bar/.*");

  registry.config().meterFilter(
    MeterFilter.replaceTagValues(Label.HTTP_PATH.toString(), actualPath -> {
      Matcher m = pattern.matcher(actualPath);
      if (m.matches()) {
        return "/foo/bar/:id";
      }
      return actualPath;
    }, ""));
}
 
Example #28
Source File: KonduitServingLauncher.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeStartingVertx(VertxOptions options) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    options.setMetricsOptions(micrometerMetricsOptions);
    options.setMaxEventLoopExecuteTime(60);
    options.setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS);
}
 
Example #29
Source File: MicrometerMetricsExamples.java    From vertx-micrometer-metrics with Apache License 2.0 4 votes vote down vote up
public void accessDefaultRegistry() {
  MeterRegistry registry = BackendRegistries.getDefaultNow();
}
 
Example #30
Source File: InferenceVerticleHttp.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
public Router createRouter() {
    InferenceHttpApi inferenceHttpApi = new InferenceHttpApi(pipelineExecutor);

    Router inferenceRouter = Router.router(vertx);
    ServiceLoader<MetricsProvider> sl = ServiceLoader.load(MetricsProvider.class);
    Iterator<MetricsProvider> iterator = sl.iterator();
    MetricsProvider metricsProvider = null;
    if (iterator.hasNext()) {
        metricsProvider = iterator.next();
    }

    Object endpoint = metricsProvider == null ? null : metricsProvider.getEndpoint();
    if (endpoint != null) {
        log.info("MetricsProvider implementation detected, adding endpoint /metrics");
        MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
                .setMicrometerRegistry(MicrometerRegistry.getRegistry())
                .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true));
        BackendRegistries.setupBackend(micrometerMetricsOptions);

        inferenceRouter.get("/metrics").handler((Handler<RoutingContext>) endpoint)
                .failureHandler(failureHandler -> {
                    if (failureHandler.failure() != null) {
                        log.error("Failed to scrape metrics", failureHandler.failure());
                    }

                    failureHandler.response()
                            .setStatusCode(500)
                            .end(failureHandler.failure().toString());
                });
    }

    inferenceRouter.post().handler(BodyHandler.create()
            .setUploadsDirectory(DirectoryFetcher.getFileUploadsDir().getAbsolutePath())
            .setDeleteUploadedFilesOnEnd(true)
            .setMergeFormAttributes(true))
            .failureHandler(failureHandler -> {
                Throwable throwable = failureHandler.failure();
                int statusCode = failureHandler.statusCode();

                if (statusCode == 404) {
                    log.warn("404 at route {}" + failureHandler.request().path());
                } else if (failureHandler.failed()) {
                    if (throwable != null) {
                        log.error("Request failed with cause ", throwable);
                    } else {
                        log.error("Request failed with unknown cause.");
                    }
                }

                if (throwable instanceof KonduitServingHttpException) {
                    sendErrorResponse(failureHandler, ((KonduitServingHttpException) throwable).getErrorResponse());
                } else {
                    failureHandler.response()
                            .setStatusCode(500)
                            .end(throwable != null ? throwable.toString() : "Internal Server Exception");
                }
            });

    inferenceRouter.post("/predict")
            .consumes(APPLICATION_JSON.toString())
            .consumes(APPLICATION_OCTET_STREAM.toString())
            .produces(APPLICATION_JSON.toString())
            .produces(APPLICATION_OCTET_STREAM.toString())
            .handler(inferenceHttpApi::predict);


    //Custom endpoints:
    if (inferenceConfiguration.customEndpoints() != null && !inferenceConfiguration.customEndpoints().isEmpty()) {
        addCustomEndpoints(inferenceHttpApi, inferenceRouter);
    }

    return inferenceRouter;
}