io.micrometer.prometheus.PrometheusConfig Java Examples

The following examples show how to use io.micrometer.prometheus.PrometheusConfig. 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: CustomMicrometerMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPublishQuantilesWithProvidedRegistry(TestContext context) throws Exception {
  PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)
        .setPublishQuantiles(true)
        .setStartEmbeddedServer(true)
        .setEmbeddedServerOptions(new HttpServerOptions().setPort(9090)))
      .setMicrometerRegistry(registry)
      .setEnabled(true)));

  Async async = context.async();
  // Dummy connection to trigger some metrics
  PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", r1 -> {
    // Delay to make "sure" metrics are populated
    vertx.setTimer(500, l -> {
      assertThat(registry.scrape()).contains("vertx_http_client_responseTime_seconds_bucket{code=\"200\"");
      async.complete();
    });
  });
  async.awaitSuccess(10000);
}
 
Example #2
Source File: CoreModule.java    From EDDI with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
public PrometheusMeterRegistry providePrometheusMeterRegistry(ExecutorService executorService,
                                                              @Named("systemRuntime.projectName") String projectName) {
    PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    new LogbackMetrics().bindTo(registry);
    new ClassLoaderMetrics().bindTo(registry);
    new ExecutorServiceMetrics(executorService,
            projectName + "-ExecutorService",
            () -> Tags.of(projectName, "ExecutorService").iterator()).bindTo(registry);
    new JvmMemoryMetrics().bindTo(registry);
    new JvmGcMetrics().bindTo(registry);
    new JvmThreadMetrics().bindTo(registry);
    new ProcessorMetrics().bindTo(registry);
    new ProcessMemoryMetrics().bindTo(registry);
    new ProcessThreadMetrics().bindTo(registry);
    new FileDescriptorMetrics().bindTo(registry);
    new DiskSpaceMetrics(new File("/")).bindTo(registry);
    new UptimeMetrics().bindTo(registry);

    registry.config().commonTags("instance", projectName);
    registry.config().commonTags("application", projectName);
    registry.config().commonTags("service", projectName);

    return registry;
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: CompareHistogramsWithOtherLibraries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Setup(Level.Iteration)
public void setup() {
    registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new CollectorRegistry(),
            Clock.SYSTEM);
    summary = DistributionSummary.builder("summary")
            .publishPercentileHistogram()
            .register(registry);
}
 
Example #10
Source File: MetricsModule.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final ServerCoreComponents coreComponents) {
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);

    if(!configuration.getBooleanProperty(METRICS_NOOP_PROPERTY, true)) {

        final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

        final List<Tag> tagList = TagUtil.convertTags(ContextManagerImpl.getInstance().getGlobalContexts());

        new ClassLoaderMetrics(tagList).bindTo(prometheusRegistry);
        new JvmMemoryMetrics(tagList).bindTo(prometheusRegistry);
        new JvmGcMetrics(tagList).bindTo(prometheusRegistry);
        new ProcessorMetrics(tagList).bindTo(prometheusRegistry);
        new JvmThreadMetrics(tagList).bindTo(prometheusRegistry);

        servletContext.addFilter(METRICS_SERVLET_FILTER_NAME, new RequestMetricsFilter())
                .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ALL_URL_MAPPING);

        servletContext.addListener(new MetricsHttpSessionListener());

        servletContext.addServlet(METRICS_SERVLET_NAME, new MetricsServlet(prometheusRegistry))
                .addMapping(configuration.getProperty(METRICS_ENDPOINT_PROPERTY));

        MetricsImpl.getInstance().init(prometheusRegistry);
    }
}
 
Example #11
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * To use pushgateway instead:
 * new PushGateway("localhost:9091").pushAdd(registry.getPrometheusRegistry(), "samples");
 *
 * @return A prometheus registry.
 */
public static PrometheusMeterRegistry prometheus() {
    PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(new PrometheusConfig() {
        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    });

    try {
        HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
        server.createContext("/prometheus", httpExchange -> {
            String response = prometheusRegistry.scrape();
            httpExchange.sendResponseHeaders(200, response.length());
            OutputStream os = httpExchange.getResponseBody();
            os.write(response.getBytes());
            os.close();
        });

        new Thread(server::start).run();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return prometheusRegistry;
}
 
Example #12
Source File: TracingConfig.java    From Mastering-Distributed-Tracing with MIT License 5 votes vote down vote up
@Bean
public PrometheusMeterRegistry micrometerRegistry(CollectorRegistry collector) {
    PrometheusMeterRegistry registry = new PrometheusMeterRegistry( //
            PrometheusConfig.DEFAULT, collector, Clock.SYSTEM);
    io.micrometer.core.instrument.Metrics.addRegistry(registry);
    return registry;
}
 
Example #13
Source File: MicrometerBasedMetricsTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets the Micrometer registries that the tests should be run against.
 *
 * @return The registries.
 */
public static Stream<MeterRegistry> registries() {
    return Stream.of(new MeterRegistry[] {
                            new PrometheusMeterRegistry(PrometheusConfig.DEFAULT),
                            new GraphiteMeterRegistry(GraphiteConfig.DEFAULT, Clock.SYSTEM)
                            });
}
 
Example #14
Source File: PrometheusMonitoringConfig.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Bean
public PrometheusMeterRegistry prometheusMeterRegistry( PrometheusConfig prometheusConfig,
    CollectorRegistry collectorRegistry, Clock clock )
{
    return new PrometheusMeterRegistry( prometheusConfig, collectorRegistry, clock );
}
 
Example #15
Source File: PrometheusSample.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

    // add any tags here that will apply to all metrics streaming from this app
    // (e.g. EC2 region, stack, instance id, server group)
    meterRegistry.config().commonTags("app", "javalin-sample");

    new JvmGcMetrics().bindTo(meterRegistry);
    new JvmHeapPressureMetrics().bindTo(meterRegistry);
    new JvmMemoryMetrics().bindTo(meterRegistry);
    new ProcessorMetrics().bindTo(meterRegistry);
    new FileDescriptorMetrics().bindTo(meterRegistry);

    Javalin app = Javalin.create(config -> config.registerPlugin(new MicrometerPlugin(meterRegistry))).start(8080);

    // must manually delegate to Micrometer exception handler for excepton tags to be correct
    app.exception(IllegalArgumentException.class, (e, ctx) -> {
        MicrometerPlugin.EXCEPTION_HANDLER.handle(e, ctx);
        e.printStackTrace();
    });

    app.get("/", ctx -> ctx.result("Hello World"));
    app.get("/hello/:name", ctx -> ctx.result("Hello: " + ctx.pathParam("name")));
    app.get("/boom", ctx -> {
        throw new IllegalArgumentException("boom");
    });

    app.routes(() -> {
        path("hi", () -> {
            get(":name", ctx -> ctx.result("Hello: " + ctx.pathParam("name")));
        });
    });

    app.after("/hello/*", ctx -> {
        System.out.println("hello");
    });

    app.get("/prometheus", ctx -> ctx
            .contentType(TextFormat.CONTENT_TYPE_004)
            .result(meterRegistry.scrape()));
}
 
Example #16
Source File: PrometheusMetricsReporterConfiguration.java    From java-metrics with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public PrometheusMeterRegistry prometheusMeterRegistry() {
    return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, collectorRegistry, Clock.SYSTEM);
}
 
Example #17
Source File: PrometheusPropertiesConfigAdapter.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean descriptions()
{
    return get( PrometheusProperties::isDescriptions, PrometheusConfig.super::descriptions );
}
 
Example #18
Source File: PrometheusPropertiesConfigAdapter.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Duration step()
{
    return get( PrometheusProperties::getStep, PrometheusConfig.super::step );
}
 
Example #19
Source File: PrometheusMonitoringConfig.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Bean
public PrometheusConfig prometheusConfig( PrometheusProperties prometheusProperties )
{
    return new PrometheusPropertiesConfigAdapter( prometheusProperties );
}
 
Example #20
Source File: MoreNamingConventionsTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
private static PrometheusMeterRegistry newPrometheusRegistry() {
    return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
}
 
Example #21
Source File: PrometheusMeterRegistryProvider.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public PrometheusMeterRegistryProvider(CollectorRegistry registry) {
  prometheusMeterRegistry =
      new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, registry, Clock.SYSTEM);
  Metrics.addRegistry(prometheusMeterRegistry);
}
 
Example #22
Source File: PrometheusMeterRegistries.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a newly-created {@link PrometheusMeterRegistry} instance with the specified
 * {@link CollectorRegistry} and {@link Clock}.
 */
public static PrometheusMeterRegistry newRegistry(CollectorRegistry registry, Clock clock) {
    final PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(
            PrometheusConfig.DEFAULT, requireNonNull(registry, "registry"), requireNonNull(clock, "clock"));
    return configureRegistry(meterRegistry);
}
 
Example #23
Source File: SpringApp.java    From rqueue with Apache License 2.0 4 votes vote down vote up
@Bean
public PrometheusMeterRegistry meterRegistry() {
  return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
}
 
Example #24
Source File: TimerBenchmark.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Setup
public void setup() {
    registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    timer = registry.timer("timer");
}
 
Example #25
Source File: CounterBenchmark.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Setup
public void setup() {
    registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    counter = registry.counter("counter");
}
 
Example #26
Source File: PrometheusBackendRegistry.java    From vertx-micrometer-metrics with Apache License 2.0 4 votes vote down vote up
public PrometheusBackendRegistry(VertxPrometheusOptions options) {
  this(options, new PrometheusMeterRegistry(PrometheusConfig.DEFAULT));
}
 
Example #27
Source File: PrometheusPropertiesConfigAdapter.java    From foremast with Apache License 2.0 4 votes vote down vote up
@Override
public Duration step() {
    return get(PrometheusProperties::getStep, PrometheusConfig.super::step);
}
 
Example #28
Source File: PrometheusPropertiesConfigAdapter.java    From foremast with Apache License 2.0 4 votes vote down vote up
@Override
public boolean descriptions() {
    return get(PrometheusProperties::isDescriptions,
        PrometheusConfig.super::descriptions);
}
 
Example #29
Source File: MetricsAutoConfiguration.java    From foremast with Apache License 2.0 4 votes vote down vote up
@Bean
public PrometheusMeterRegistry prometheusMeterRegistry(PrometheusConfig config, CollectorRegistry collectorRegistry,
                                                       Clock clock) {
    return new PrometheusMeterRegistry(config, collectorRegistry, clock);
}
 
Example #30
Source File: MetricsAutoConfiguration.java    From foremast with Apache License 2.0 4 votes vote down vote up
@Bean
public PrometheusConfig prometheusConfig() {
    return new PrometheusPropertiesConfigAdapter(prometheusProperties);
}