Search in sources :

Example 1 with MetricsServlet

use of com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet in project dolphin-platform by canoo.

the class MetricsModule method initialize.

@Override
public void initialize(final ServerCoreComponents coreComponents) {
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    if (!configuration.getBooleanProperty(METRICS_NOOP_PROPERTY, true)) {
        final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
        final List<Tag> tagList = TagUtil.convertTags(ContextManagerImpl.getInstance().getGlobalContexts());
        new ClassLoaderMetrics(tagList).bindTo(prometheusRegistry);
        new JvmMemoryMetrics(tagList).bindTo(prometheusRegistry);
        new JvmGcMetrics(tagList).bindTo(prometheusRegistry);
        new ProcessorMetrics(tagList).bindTo(prometheusRegistry);
        new JvmThreadMetrics(tagList).bindTo(prometheusRegistry);
        servletContext.addFilter(METRICS_SERVLET_FILTER_NAME, new RequestMetricsFilter()).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ALL_URL_MAPPING);
        servletContext.addListener(new MetricsHttpSessionListener());
        servletContext.addServlet(METRICS_SERVLET_NAME, new MetricsServlet(prometheusRegistry)).addMapping(configuration.getProperty(METRICS_ENDPOINT_PROPERTY));
        MetricsImpl.getInstance().init(prometheusRegistry);
    }
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) ProcessorMetrics(io.micrometer.core.instrument.binder.system.ProcessorMetrics) RequestMetricsFilter(com.canoo.dp.impl.platform.server.metrics.servlet.RequestMetricsFilter) JvmMemoryMetrics(io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics) JvmGcMetrics(io.micrometer.core.instrument.binder.jvm.JvmGcMetrics) ClassLoaderMetrics(io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics) JvmThreadMetrics(io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics) MetricsHttpSessionListener(com.canoo.dp.impl.platform.server.metrics.servlet.MetricsHttpSessionListener) MetricsServlet(com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet) ServletContext(javax.servlet.ServletContext) Tag(io.micrometer.core.instrument.Tag) DispatcherType(javax.servlet.DispatcherType)

Aggregations

MetricsHttpSessionListener (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsHttpSessionListener)1 MetricsServlet (com.canoo.dp.impl.platform.server.metrics.servlet.MetricsServlet)1 RequestMetricsFilter (com.canoo.dp.impl.platform.server.metrics.servlet.RequestMetricsFilter)1 PlatformConfiguration (com.canoo.platform.core.PlatformConfiguration)1 Tag (io.micrometer.core.instrument.Tag)1 ClassLoaderMetrics (io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics)1 JvmGcMetrics (io.micrometer.core.instrument.binder.jvm.JvmGcMetrics)1 JvmMemoryMetrics (io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics)1 JvmThreadMetrics (io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics)1 ProcessorMetrics (io.micrometer.core.instrument.binder.system.ProcessorMetrics)1 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)1 DispatcherType (javax.servlet.DispatcherType)1 ServletContext (javax.servlet.ServletContext)1