博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringMVC集成zipkin性能监控
阅读量:5259 次
发布时间:2019-06-14

本文共 4489 字,大约阅读时间需要 14 分钟。

一:导入jar包

3.16.0
0.6.9
​​
io.zipkin.brave
brave-core-spring
${brave.version}
io.zipkin.reporter
zipkin-sender-okhttp3
${zipkin-reporter.version}
io.zipkin.reporter
zipkin-sender-libthrift
${zipkin-reporter.version}
io.zipkin.reporter
zipkin-sender-kafka08
${zipkin-reporter.version}
io.zipkin.brave
brave-spring-web-servlet-interceptor
${brave.version}
io.zipkin.brave
brave-spring-resttemplate-interceptors
${brave.version}

  

二:配置前端过滤器(如已配置请忽略)

三:写自定义配置类

package com.mzx.controller;    /**     * @Param:     * @return:     * @Author: Mr.Meng     * @Date: 2018/10/24     */import com.github.kristofa.brave.Brave;import com.github.kristofa.brave.http.DefaultSpanNameProvider;import com.github.kristofa.brave.http.SpanNameProvider;import com.github.kristofa.brave.spring.BraveClientHttpRequestInterceptor;import com.github.kristofa.brave.spring.ServletHandlerInterceptor;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Import;import org.springframework.http.client.ClientHttpRequestInterceptor;import org.springframework.web.client.RestTemplate;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import zipkin.Span;import zipkin.reporter.AsyncReporter;import zipkin.reporter.Reporter;import zipkin.reporter.Sender;import zipkin.reporter.okhttp3.OkHttpSender;​import javax.annotation.PostConstruct;import java.util.ArrayList;import java.util.List;​/** * This adds tracing configuration to any web mvc controllers or rest template clients. This should * be configured last. */@Configuration @EnableWebMvc// import as the interceptors are annotation with javax.inject and not automatically wired@Import({BraveClientHttpRequestInterceptor.class, ServletHandlerInterceptor.class})public class WebTracingConfiguration extends WebMvcConfigurerAdapter {    /** Configuration for how to send spans to Zipkin */    @Bean    Sender sender() {        return OkHttpSender.create("http://127.0.0.1:9411/api/v1/spans");        //return LibthriftSender.create("127.0.0.1");        // return KafkaSender.create("127.0.0.1:9092");    }​    /** Configuration for how to buffer spans into messages for Zipkin */    @Bean    Reporter reporter() {        // return new LoggingReporter(); // Just log json info!!!        // uncomment to actually send to zipkin!        return AsyncReporter.builder(sender()).build();    }​    @Bean    Brave brave() {        return new Brave.Builder("这里写项目业务名称").reporter(reporter()).build();    }​    // decide how to name spans. By default they are named the same as the http method.    @Bean    SpanNameProvider spanNameProvider() {        return new DefaultSpanNameProvider();    }    @Bean    RestTemplate template() {        return new RestTemplate();    }​    @Autowired    private ServletHandlerInterceptor serverInterceptor;​    @Autowired    private BraveClientHttpRequestInterceptor clientInterceptor;​    @Autowired    private RestTemplate restTemplate;​    // adds tracing to the application-defined rest template    @PostConstruct    public void init() {        List
interceptors = new ArrayList
(restTemplate.getInterceptors()); interceptors.add(clientInterceptor); restTemplate.setInterceptors(interceptors); }​ // adds tracing to the application-defined web controllers @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(serverInterceptor); }}

  

 

转载于:https://www.cnblogs.com/mengyixin/p/9850765.html

你可能感兴趣的文章
制作满天星空
查看>>
类和结构
查看>>
CSS3选择器(二)之属性选择器
查看>>
adidas crazylight 2018 performance analysis review
查看>>
typeset shell 用法
查看>>
python 之 循环语句
查看>>
心得25--JDK新特性9-泛型1-加深介绍
查看>>
[转]ceph网络通信模块_以monitor模块为例
查看>>
HDOJ 1754 I Hate It(线段树基本操作)
查看>>
latex tree
查看>>
安装NVIDIA驱动时禁用自带nouveau驱动
查看>>
HDU-1255 覆盖的面积 (扫描线)
查看>>
css3学习01
查看>>
【USACO】 奶牛会展
查看>>
ActiveMQ笔记之点对点队列(Point-to-Point)
查看>>
继承和多态
查看>>
Dijkstra+计算几何 POJ 2502 Subway
查看>>
修复IE不能执行JS的方法
查看>>
程序员究竟该如何提高效率zt
查看>>
希尔排序法(缩小增量法)
查看>>