Search in sources :

Example 1 with PrometheusConfig

use of io.micrometer.prometheus.PrometheusConfig in project spring-boot by spring-projects.

the class PrometheusPropertiesTests method defaultValuesAreConsistent.

@Test
void defaultValuesAreConsistent() {
    PrometheusProperties properties = new PrometheusProperties();
    PrometheusConfig config = PrometheusConfig.DEFAULT;
    assertThat(properties.isDescriptions()).isEqualTo(config.descriptions());
    assertThat(properties.getHistogramFlavor()).isEqualTo(config.histogramFlavor());
    assertThat(properties.getStep()).isEqualTo(config.step());
}
Also used : PrometheusConfig(io.micrometer.prometheus.PrometheusConfig) Test(org.junit.jupiter.api.Test)

Example 2 with PrometheusConfig

use of io.micrometer.prometheus.PrometheusConfig 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)

Aggregations

PrometheusConfig (io.micrometer.prometheus.PrometheusConfig)2 HttpServer (com.sun.net.httpserver.HttpServer)1 Nullable (io.micrometer.core.lang.Nullable)1 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1