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;
}
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");
}
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);
}
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;
}
Aggregations