栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Dropwizard指标和spring-mvc实施统计信息

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Dropwizard指标和spring-mvc实施统计信息

您可以将指标用于Spring。这是一个github链接,它说明了如何将其与Spring MVC集成。metrics-spring模块将Dropwizard
Metrics库
与Spring
集成在一起,并提供XML和Java配置。

马文

当前版本是3.1.2,与Metrics 3.1.2兼容

<dependency>    <groupId>com.ryantenney.metrics</groupId>    <artifactId>metrics-spring</artifactId>    <version>3.1.2</version></dependency>

基本用法

从版本3开始,可以根据您的个人喜好使用XML或Java配置metrics-spring。

XML配置:

<beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:metrics="http://www.ryantenney.com/schema/metrics"       xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.ryantenney.com/schema/metricshttp://www.ryantenney.com/schema/metrics/metrics.xsd">    <!-- Creates a MetricRegistry bean -->    <metrics:metric-registry id="metricRegistry" />    <!-- Creates a HealthCheckRegistry bean (Optional) -->    <metrics:health-check-registry id="health" />    <!-- Registers BeanPostProcessors with Spring which proxy beans and capture metrics -->    <!-- Include this once per context (once in the parent context and in any subcontexts) -->    <metrics:annotation-driven metric-registry="metricRegistry" />    <!-- Example reporter definiton. Supported reporters include jmx, slf4j, graphite, and others. -->    <!-- Reporters should be defined only once, preferably in the parent context -->    <metrics:reporter type="console" metric-registry="metricRegistry" period="1m" />    <!-- Register metric beans (Optional) -->    <!-- The metrics in this example require metrics-jvm -->    <metrics:register metric-registry="metricRegistry">        <bean metrics:name="jvm.gc"  />        <bean metrics:name="jvm.memory"  />        <bean metrics:name="jvm.thread-states"  />        <bean metrics:name="jvm.fd.usage"  />    </metrics:register>    <!-- Beans and other Spring config --></beans>

Java配置:

import java.util.concurrent.TimeUnit;import org.springframework.context.annotation.Configuration;import com.codahale.metrics.ConsoleReporter;import com.codahale.metrics.MetricRegistry;import com.codahale.metrics.SharedMetricRegistries;import com.ryantenney.metrics.spring.config.annotation.EnableMetrics;import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;@Configuration@EnableMetricspublic class SpringConfiguringClass extends MetricsConfigurerAdapter {    @Override    public void configureReporters(MetricRegistry metricRegistry) {        // registerReporter allows the MetricsConfigurerAdapter to        // shut down the reporter when the Spring context is closed        registerReporter(ConsoleReporter .forRegistry(metricRegistry) .build()) .start(1, TimeUnit.MINUTES);    }}

阅读更多有关Metrics Spring



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/452201.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号