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.pswp.cn/news/259789.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/259789.shtml
英文地址,請注明出處:http://en.pswp.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;對…