Search in sources :

Example 6 with PrometheusMeterRegistry

use of io.micrometer.prometheus.PrometheusMeterRegistry in project micrometer by micrometer-metrics.

the class SampleRegistries method prometheus.

/**
 * 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;
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) HttpServer(com.sun.net.httpserver.HttpServer) PrometheusConfig(io.micrometer.prometheus.PrometheusConfig) Duration(java.time.Duration) IOException(java.io.IOException) Nullable(io.micrometer.core.lang.Nullable)

Example 7 with PrometheusMeterRegistry

use of io.micrometer.prometheus.PrometheusMeterRegistry in project micrometer by micrometer-metrics.

the class TimerBenchmark method setup.

@Setup
public void setup() {
    registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    timer = registry.timer("timer");
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry)

Example 8 with PrometheusMeterRegistry

use of io.micrometer.prometheus.PrometheusMeterRegistry in project vertx-micrometer-metrics by vert-x3.

the class PrometheusMetricsITest method shouldBindExistingServer.

@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::accept).listen(8081);
    Async async = context.async();
    HttpClientRequest req = vertx.createHttpClient().get(8081, "localhost", "/custom").handler(res -> {
        context.assertEquals(200, res.statusCode());
        res.bodyHandler(body -> {
            context.verify(v -> assertThat(body.toString()).contains("vertx_http_"));
            async.complete();
        });
    });
    req.end();
    async.awaitSuccess(10000);
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) HttpClientRequest(io.vertx.core.http.HttpClientRequest) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Async(io.vertx.ext.unit.Async) Router(io.vertx.ext.web.Router) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) Test(org.junit.Test)

Example 9 with PrometheusMeterRegistry

use of io.micrometer.prometheus.PrometheusMeterRegistry in project zipkin by openzipkin.

the class ZipkinPrometheusMetricsConfiguration method prometheusMeterRegistry.

@Bean
@ConditionalOnMissingBean
public PrometheusMeterRegistry prometheusMeterRegistry(PrometheusConfig config, CollectorRegistry registry, Clock clock) {
    PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(config, registry, clock);
    new JvmMemoryMetrics().bindTo(meterRegistry);
    new JvmGcMetrics().bindTo(meterRegistry);
    new JvmThreadMetrics().bindTo(meterRegistry);
    new ClassLoaderMetrics().bindTo(meterRegistry);
    new ProcessorMetrics().bindTo(meterRegistry);
    return meterRegistry;
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) ClassLoaderMetrics(io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics) JvmThreadMetrics(io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics) ProcessorMetrics(io.micrometer.core.instrument.binder.system.ProcessorMetrics) JvmMemoryMetrics(io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics) JvmGcMetrics(io.micrometer.core.instrument.binder.jvm.JvmGcMetrics) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)9 ClassLoaderMetrics (io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics)3 JvmMemoryMetrics (io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics)3 JvmThreadMetrics (io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics)3 ProcessorMetrics (io.micrometer.core.instrument.binder.system.ProcessorMetrics)3 JvmGcMetrics (io.micrometer.core.instrument.binder.jvm.JvmGcMetrics)2 VertxOptions (io.vertx.core.VertxOptions)2 Router (io.vertx.ext.web.Router)2 MicrometerMetricsOptions (io.vertx.micrometer.MicrometerMetricsOptions)2 VertxPrometheusOptions (io.vertx.micrometer.VertxPrometheusOptions)2 MetricsHttpSessionListener (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsHttpSessionListener)1 MetricsServlet (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet)1 RequestMetricsFilter (com.canoo.dp.impl.platform.server.metrics.servlet.RequestMetricsFilter)1 PlatformConfiguration (com.canoo.platform.core.PlatformConfiguration)1 HttpServer (com.sun.net.httpserver.HttpServer)1 Metrics (com.uber.jaeger.metrics.Metrics)1 Tag (io.micrometer.core.instrument.Tag)1 FileDescriptorMetrics (io.micrometer.core.instrument.binder.system.FileDescriptorMetrics)1 UptimeMetrics (io.micrometer.core.instrument.binder.system.UptimeMetrics)1 Nullable (io.micrometer.core.lang.Nullable)1