use of io.prometheus.client.hotspot.StandardExports in project bookkeeper by apache.
the class PrometheusMetricsProvider method start.
@Override
public void start(Configuration conf) {
int httpPort = conf.getInt(PROMETHEUS_STATS_HTTP_PORT, DEFAULT_PROMETHEUS_STATS_HTTP_PORT);
InetSocketAddress httpEndpoint = InetSocketAddress.createUnresolved("0.0.0.0", httpPort);
this.server = new Server(httpEndpoint);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new PrometheusServlet(this)), "/metrics");
try {
server.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
// Include standard JVM stats
new StandardExports().register(registry);
new MemoryPoolsExports().register(registry);
new GarbageCollectorExports().register(registry);
new ThreadExports().register(registry);
// Add direct memory allocated through unsafe
Gauge.build("jvm_memory_direct_bytes_used", "-").create().setChild(new Child() {
@Override
public double get() {
return directMemoryUsage != null ? directMemoryUsage.longValue() : Double.NaN;
}
}).register(registry);
Gauge.build("jvm_memory_direct_bytes_max", "-").create().setChild(new Child() {
@Override
public double get() {
return PlatformDependent.maxDirectMemory();
}
}).register(registry);
executor = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("metrics"));
int latencyRolloverSeconds = conf.getInt(PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS, DEFAULT_PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS);
executor.scheduleAtFixedRate(() -> {
rotateLatencyCollection();
}, 1, latencyRolloverSeconds, TimeUnit.SECONDS);
log.info("Started Prometheus stats endpoint at {}", httpEndpoint);
}
use of io.prometheus.client.hotspot.StandardExports in project MantaroBot by Mantaro.
the class Prometheus method enable.
public static void enable() throws IOException {
if (STATE.compareAndSet(State.DISABLED, State.ENABLING)) {
// replaced by jfr? needs testing, if yes then remove
// used for cpu usage
new StandardExports().register();
// replaced by jfr? needs testing, if yes then remove
// used for memory usage
new MemoryPoolsExports().register();
// ig we can keep this one for now
new BufferPoolsExports().register();
JFRExports.register();
var config = MantaroData.config().get();
server = new HTTPServer(config.prometheusHost, config.prometheusPort);
STATE.set(State.ENABLED);
}
}
Aggregations