Zipkin-1.19.0学习系列1:java范例

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

官网地址: 

https://github.com/openzipkin/zipkin

http://zipkin.io/

https://www.oschina.net/p/zipkin

截止到2017/1/4为止,最新版本为: Zipkin 1.19

下载地址: https://github.com/openzipkin/zipkin/archive/1.19.0.tar.gz

---

下载后,上传到我的linux上,解压缩,大概看了下,去掉一些不需要的代码块,java文件数也不是很多。

 

接下来开始编译,根据官网的说明,http://zipkin.io/pages/quickstart

./mvnw -DskipTests --also-make -pl zipkin-server clean install

网速太慢。。。

直接上https://search.maven.org/#search%7Cga%7C1%7Cio.zipkin.java%20zipkin-server下载现成的jar包下来。

java -jar ....jar启动

然后找了这样一篇文章

package brave;import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;import com.github.kristofa.brave.Brave;
import com.github.kristofa.brave.ClientRequestAdapter;
import com.github.kristofa.brave.ClientRequestInterceptor;
import com.github.kristofa.brave.ClientResponseAdapter;
import com.github.kristofa.brave.ClientResponseInterceptor;
import com.github.kristofa.brave.EmptySpanCollectorMetricsHandler;
import com.github.kristofa.brave.KeyValueAnnotation;
import com.github.kristofa.brave.ServerRequestAdapter;
import com.github.kristofa.brave.ServerRequestInterceptor;
import com.github.kristofa.brave.ServerResponseAdapter;
import com.github.kristofa.brave.ServerResponseInterceptor;
import com.github.kristofa.brave.SpanId;
import com.github.kristofa.brave.TraceData;
import com.github.kristofa.brave.http.HttpSpanCollector;
import com.twitter.zipkin.gen.Endpoint;//https://my.oschina.net/u/223522/blog/736852-一个例子 
//http://www.tuicool.com/articles/f2qAZnZ-servlet
public class Test {private static HttpSpanCollector collector = null;private static Brave brave = null;private static Brave brave2 = null;private static void braveInit(){collector = HttpSpanCollector.create("http://102.45.78.213:9411/", new EmptySpanCollectorMetricsHandler());brave = new Brave.Builder("appserver").spanCollector(collector).build();brave2 = new Brave.Builder("datacenter").spanCollector(collector).build();}static class Task {String name;SpanId spanId;public Task(String name, SpanId spanId) {super();this.name = name;this.spanId = spanId;}}public static void main(String[] args) throws Exception {braveInit();final BlockingQueue<Task> queue = new ArrayBlockingQueue<Task>(10);Thread thread = new Thread(){public void run() {while (true) {try {Task task = queue.take();dcHandle(task.name, task.spanId);} catch (Exception e) {e.printStackTrace();}}}};thread.start();{ServerRequestInterceptor serverRequestInterceptor = brave.serverRequestInterceptor();ServerResponseInterceptor serverResponseInterceptor = brave.serverResponseInterceptor();ClientRequestInterceptor clientRequestInterceptor = brave.clientRequestInterceptor();ClientResponseInterceptor clientResponseInterceptor = brave.clientResponseInterceptor();serverRequestInterceptor.handle(new ServerRequestAdapterImpl("group_data"));ClientRequestAdapterImpl clientRequestAdapterImpl = new ClientRequestAdapterImpl("get_radio_list");clientRequestInterceptor.handle(clientRequestAdapterImpl);queue.offer(new Task("get_radio_list", clientRequestAdapterImpl.getSpanId()));Thread.sleep(10);clientResponseInterceptor.handle(new ClientResponseAdapterImpl());clientRequestAdapterImpl = new ClientRequestAdapterImpl("get_user_list");clientRequestInterceptor.handle(clientRequestAdapterImpl);queue.offer(new Task("get_user_list", clientRequestAdapterImpl.getSpanId()));Thread.sleep(10);clientResponseInterceptor.handle(new ClientResponseAdapterImpl());clientRequestAdapterImpl = new ClientRequestAdapterImpl("get_program_list");clientRequestInterceptor.handle(clientRequestAdapterImpl);queue.offer(new Task("get_program_list", clientRequestAdapterImpl.getSpanId()));Thread.sleep(10);clientResponseInterceptor.handle(new ClientResponseAdapterImpl());serverResponseInterceptor.handle(new ServerResponseAdapterImpl());}Thread.sleep(3000);}public static void dcHandle(String spanName, SpanId spanId){ServerRequestInterceptor serverRequestInterceptor = brave2.serverRequestInterceptor();ServerResponseInterceptor serverResponseInterceptor = brave2.serverResponseInterceptor();serverRequestInterceptor.handle(new ServerRequestAdapterImpl(spanName, spanId));serverResponseInterceptor.handle(new ServerResponseAdapterImpl());}static class ServerRequestAdapterImpl implements ServerRequestAdapter {Random randomGenerator = new Random();SpanId spanId;String spanName;ServerRequestAdapterImpl(String spanName){this.spanName = spanName;long startId = randomGenerator.nextLong();SpanId spanId = SpanId.builder().spanId(startId).traceId(startId).parentId(startId).build();this.spanId = spanId;}ServerRequestAdapterImpl(String spanName, SpanId spanId){this.spanName = spanName;this.spanId = spanId;}@Overridepublic TraceData getTraceData() {if (this.spanId != null) {return TraceData.builder().spanId(this.spanId).build();}long startId = randomGenerator.nextLong();SpanId spanId = SpanId.builder().spanId(startId).traceId(startId).parentId(startId).build();return TraceData.builder().spanId(spanId).build();}@Overridepublic String getSpanName() {return spanName;}@Overridepublic Collection<KeyValueAnnotation> requestAnnotations() {Collection<KeyValueAnnotation> collection = new ArrayList<KeyValueAnnotation>();KeyValueAnnotation kv = KeyValueAnnotation.create("radioid", "165646485468486364");collection.add(kv);return collection;}}static class ServerResponseAdapterImpl implements ServerResponseAdapter {@Overridepublic Collection<KeyValueAnnotation> responseAnnotations() {Collection<KeyValueAnnotation> collection = new ArrayList<KeyValueAnnotation>();KeyValueAnnotation kv = KeyValueAnnotation.create("radioid", "165646485468486364");collection.add(kv);return collection;}}static class ClientRequestAdapterImpl implements ClientRequestAdapter {String spanName;SpanId spanId;ClientRequestAdapterImpl(String spanName){this.spanName = spanName;}public SpanId getSpanId() {return spanId;}@Overridepublic String getSpanName() {return this.spanName;}@Overridepublic void addSpanIdToRequest(SpanId spanId) {//记录传输到远程服务System.out.println(spanId);if (spanId != null) {this.spanId = spanId;System.out.println(String.format("trace_id=%s, parent_id=%s, span_id=%s", spanId.traceId, spanId.parentId, spanId.spanId));}}@Overridepublic Collection<KeyValueAnnotation> requestAnnotations() {Collection<KeyValueAnnotation> collection = new ArrayList<KeyValueAnnotation>();KeyValueAnnotation kv = KeyValueAnnotation.create("radioid", "165646485468486364");collection.add(kv);return collection;}@Overridepublic Endpoint serverAddress() {return null;}}static class ClientResponseAdapterImpl implements ClientResponseAdapter {@Overridepublic Collection<KeyValueAnnotation> responseAnnotations() {Collection<KeyValueAnnotation> collection = new ArrayList<KeyValueAnnotation>();KeyValueAnnotation kv = KeyValueAnnotation.create("radioname", "火星人1");collection.add(kv);return collection;}}
}

maven文件如下:

<dependencies><dependency><groupId>io.zipkin.brave</groupId><artifactId>brave-spancollector-http</artifactId><version>3.9.0</version></dependency></dependencies>

查看上报的效果

转载于:https://my.oschina.net/qiangzigege/blog/818711

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/259789.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

PageRank算法

1. PageRank算法概述 PageRank,即网页排名&#xff0c;又称网页级别、Google左側排名或佩奇排名。 是Google创始人拉里佩奇和谢尔盖布林于1997年构建早期的搜索系统原型时提出的链接分析算法&#xff0c;自从Google在商业上获得空前的成功后&#xff0c;该算法也成为其他搜索引…

linux中_在 Linux 桌面中开始使用 Lumina | Linux 中国

本文是 24 天 Linux 桌面特别系列的一部分。Lumina 桌面是让你使用快速、合理的基于 Fluxbox 桌面的捷径&#xff0c;它具有你无法缺少的所有功能。-- Seth Kenlon多年来&#xff0c;有一个名为 PC-BSD 的基于 FreeBSD 的桌面操作系统(OS)。它旨在作为一个常规使用的系统&#…

弹体飞行姿态仿真软件程序代写

题目弹体飞行姿态仿真软件毕业设计的任务和要求&#xff08;1&#xff09;掌握查阅参考文献的方法 &#xff08;2&#xff09;对弹体飞行运行学模型有所研究 &#xff08;3&#xff09;在给定初始俯仰角、加速度、弹体质量等参数的前提下&#xff0c;完成弹体飞行轨迹的绘制及不…

Asp.net中实现同一用户名同时登陆,注销先前用户(转)

Web 项目中经常遇到的问题就是同一用户名多次登陆的问题&#xff0c;相应的解决办法也很多&#xff0c;总结起来不外乎这几种解决办法&#xff1a;将登陆后的用户名放到数据库表中&#xff1b;登陆后的用 户名放到Session中&#xff1b;登陆后的用户名放到Application中&#x…

hdu 2612 Find a way (广搜)

Problem DescriptionPass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.Yifenfei’s home is at the countryside, but Merceki’s home is in t…

使用Notepad++开发C#,一个复杂点的csscript脚本

使用Notepad开发C#&#xff0c;一个复杂点的csscript脚本&#xff1a; 12345678910111213141516171819//css_dir ....lib;//css_ref Geb.Image.dll;//css_ref Geb.Image.ShapeAnalysis.dll;//css_ref Geb.Utils.dll;//css_ref Geb.Utils.WinForm.dll;//css_co /unsafe; using S…

正则表达式里转义字符_五分钟搞定正则表达式,如果没搞定,再加两分钟

五分钟搞定正则表达式&#xff0c;如果没搞定&#xff0c;再加两分钟【这是 ZY 第 18 篇原创文章】 文章概览一、正则表达式介绍正则表达式&#xff0c;又称规则表达式。&#xff08;英语&#xff1a;Regular Expression&#xff0c;在代码中常简写为regex、regexp或RE&#xf…

百度富文本编辑器,改变图片上传存储路径

我用的是最新版&#xff01; 找到以下2个关键文件&#xff1a; YourPath.../Ueditor/php/config.json YourPath.../Ueditor/php/Uploader.class.php config.json找到如下代码&#xff1a; "imagePathFormat": "...(这里不用管)",//找到imagePathFormat所在…

如何手动给Docker容器设置静态IP

2019独角兽企业重金招聘Python工程师标准>>> 要点&#xff1a; 1.首先需要在宿主机上虚拟出来一个真实可用桥接网卡比如br0 2.docker启动的时候默认使用br0进行桥接网络 3.创建docker容器的时候使用--netnone模式 4.手动为每个创建的容器生成静态ip。但是ip每次在重…

获取滚动条宽度代码(记录)

1.创建一个嵌套节点&#xff0c;让外层节点产生滚动条。 2.用offsetWidth - clientWidth 即可获得滚动条宽度。 为了避免页面抖动&#xff0c;可以设置外层元素position:absolute和visibility:hidden 代码如下&#xff1a; 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHT…

的函数原型_JS基础函数、对象和原型、原型链的关系

JS的原型、原型链一直是比较难理解的内容&#xff0c;不少初学者甚至有一定经验的老鸟都不一定能完全说清楚&#xff0c;更多的"很可能"是一知半解&#xff0c;而这部分内容又是JS的核心内容&#xff0c;想要技术进阶的话肯定不能对这个概念一知半解&#xff0c;碰到…

python字符串基本操作

直接上图&#xff1a; ispace()是否为空格 isupper()与islower是否为大写或小写 isdigit是否为数字 isalpha是否为字母 isalnum()是否为字母与数字混合体 startswith()与endswith()判断是否以什么开始&#xff0c;以什么结尾转载于:https://www.cnblogs.com/bestSmile/p/405550…

迁移学习自我学习

最近在看Ng的深度学习教程&#xff0c;看到self-taught learning的时候&#xff0c;对一些概念感到很陌生。作为还清技术债的一个环节&#xff0c;用半个下午的时间简单搜了下几个名词&#xff0c;以后如果会用到的话再深入去看。 监督学习在前一篇博客中讨论过了&#xff0c;这…

堰流实验报告思考题_堰流流量系数测定实验

二、实验操作部分1&#xff0e;实验操作过程(可用图表示)2&#xff0e;实验数据、表格及数据处理3&#xff0e;结论1.实验步骤(1)放水之前&#xff0c;用活动测针测出堰前槽底高程▽低和堰顶高程▽堰顶&#xff0c;堰高P▽堰顶-▽底。(2)关闭首部的泄水阀&#xff0c;打开进水阀…

WCF全双工以及用户名密码验证

WCF是支持TCP双向连接的&#xff0c;支持Server和Client之间互发协议&#xff0c;通过 订阅-发布 的全双工形式实现&#xff0c;全双工的用户名密码验证需要X509证书加密&#xff0c;单工模式的用户名密码验证时&#xff0c;X509证书是可选的。 在全双工模式下&#xff0c;会有…

MTV: Django眼中的MVC

URLconfMTV&#xff1a;Django眼中的MVC MVC是众所周知的模式&#xff0c;即&#xff1a;将应用程序分解成三个组成部分:model(模型),view(视图),和 controller(控制 器)。其中&#xff1a;M 管理应用程序的状态&#xff08;通常存储到数据库中&#xff09;&#xff0c;并约束改…

createbitmap导致的内存泄漏如何处理_C++ 如何避免内存泄漏,一篇就够

前言近年来&#xff0c;讨论 C 的人越来越少了&#xff0c;一方面是由于像 Python&#xff0c;Go 等优秀的语言的流行&#xff0c;另一方面&#xff0c;大家也越来越明白一个道理&#xff0c;并不是所有的场景都必须使用 C 进行开发。Python 可以应付大部分对性能要求不高的场景…

Visio绘制功能分解图

为什么要绘制功能分解图&#xff1f; 对于编程人员来说&#xff0c;具体分配任务的时候&#xff0c;必须知道自己要做什么&#xff0c;必须了解系统的大体框架。功能分解图可以帮助我们理清程序的框架&#xff0c;便于大局观的掌握。 用Visio2010创建功能分解图 1、选择模版 2、…

Heka:Go编写,来自Mozilla,高效、灵活的插件式数据挖掘工具(转)

转自&#xff1a;http://www.csdn.net/article/2013-05-02/2815116-introduce-from-mozilla-heka-go摘要&#xff1a;一直崇尚开源的Mozilla近日释放了Heka测试版——插件架构&#xff0c;Go编写。在支持使用Go扩展功能的同时&#xff0c;还通过允许“Sandboxed Filters”提供了…

cocos2d学习笔记2——学习资源

1. 视频 找了好几个视频&#xff0c;有一些讲得好的文件资源没有&#xff0c;后来终于找到一个讲得不错还有文件资源的&#xff0c;还有高清下载地址&#xff0c;虽然是2.2版本的&#xff0c;但是确实能学到不少东西&#xff0c;对用cocos2d做游戏有了基本的印象&#xff0c;对…