package io.vertx.micrometer.impl;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.vertx.core.VertxOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.core.metrics.MetricsOptions;
import io.vertx.core.spi.VertxMetricsFactory;
import io.vertx.core.spi.metrics.VertxMetrics;
import io.vertx.micrometer.MicrometerMetricsOptions;
import io.vertx.micrometer.backends.BackendRegistries;
import io.vertx.micrometer.backends.BackendRegistry;
public class VertxMetricsFactoryImpl implements VertxMetricsFactory {
@Override
public VertxMetrics metrics(VertxOptions vertxOptions) {
MetricsOptions metricsOptions = vertxOptions.getMetricsOptions();
MicrometerMetricsOptions options;
if (metricsOptions instanceof MicrometerMetricsOptions) {
options = (MicrometerMetricsOptions) metricsOptions;
} else {
options = new MicrometerMetricsOptions(metricsOptions.toJson());
}
BackendRegistry backendRegistry = BackendRegistries.setupBackend(options);
VertxMetricsImpl metrics = new VertxMetricsImpl(options, backendRegistry);
metrics.init();
if (options.isJvmMetricsEnabled()) {
new ClassLoaderMetrics().bindTo(backendRegistry.getMeterRegistry());
new JvmMemoryMetrics().bindTo(backendRegistry.getMeterRegistry());
new JvmGcMetrics().bindTo(backendRegistry.getMeterRegistry());
new ProcessorMetrics().bindTo(backendRegistry.getMeterRegistry());
new JvmThreadMetrics().bindTo(backendRegistry.getMeterRegistry());
}
return metrics;
}
@Override
public MetricsOptions newOptions() {
return newOptions(null);
}
@Override
public MetricsOptions newOptions(JsonObject jsonObject) {
return jsonObject == null ? new MicrometerMetricsOptions() : new MicrometerMetricsOptions(jsonObject);
}
}