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