從零開始:zipkin
一、工作環境
作業系統:Ubuntu 16.04
java環境:JDK 1.8
SpringBoot版本:1.5.13
SpringCloud版本:Edgware.SR3
二、專案配置
1. zipkin Server
pom.xml
<dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-server</artifactId> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-autoconfigure-ui</artifactId> <scope>runtime</scope> </dependency>
application.yml
server:
port: 9411
ZipkinApplication.java
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import zipkin.server.EnableZipkinServer; @SpringBootApplication @EnableZipkinServer public class ZipkinApplication { public static void main(String[] args) { SpringApplication.run(ZipkinApplication.class, args); } }
2. zipkin client
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
application.yml
spring: zipkin: base-url: http://zipkin-server:9411 //zipkin server的地址 sleuth: sampler: percentage: 0.1 //監測比例,預設為0.1,設定為1則為每次http動作都監控,但是對效能會有影響
細心的小夥伴可能發現了zipkin-client除了配置檔案並沒有對專案檔案作任何修改,這是因為zipkin的工作原理是一旦監測到feign或者RestTemplate呼叫api介面就會自動將當前專案的本次http操作上傳到配置檔案裡的zipkin server中。
因為每個專案的zipkin只能監控當前專案,而一次http會話中必定會有request和response,那麼兩個專案都需要作為zipkin client新增依賴。
三、測試
用postman多訪問幾次zipkin client的url,防止未監控到資料(我這裡被坑慘了。。一直都以為是配置錯誤導致沒資料,警醒後面的小夥伴)
獲取到http資料!
四、參考
五、不定期更新
1. zipkin使用mysql進行持久化
預設情況下zipkin將資料儲存在記憶體中(zipkin.storage.type=mem),一旦重啟服務資料全部丟失,不適合生產環境
pom新增依賴
<!--儲存到資料庫需要如下依賴-->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-mysql</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
application.yml新增資料庫相關配置
zipkin:
storage:
type: mysql
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST}:${MYSQL_TCP_PORT}/${MYSQL_DB}?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
username: ${MYSQL_USERNAME}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.jdbc.Driver
環境變數請根據不同情況自行設定,除了資料庫使用者名稱和密碼外都有預設配置(使用者名稱和密碼預設為空),預設配置如下:
host: ${MYSQL_HOST:localhost} // 資料庫IP
port: ${MYSQL_TCP_PORT:3306} // 資料庫埠
username: ${MYSQL_USER:} // 使用者名稱
password: ${MYSQL_PASS:} // 密碼
db: ${MYSQL_DB:zipkin} // 預設連線的資料庫名稱
max-active: ${MYSQL_MAX_CONNECTIONS:10} // 資料庫最大連線數
use-ssl: ${MYSQL_USE_SSL:false} // 資料庫是否使用ssl連線
zipkin.sql
CREATE TABLE IF NOT EXISTS zipkin_spans (
`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
`trace_id` BIGINT NOT NULL,
`id` BIGINT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`parent_id` BIGINT,
`debug` BIT(1),
`start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',
`duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate';
ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations';
ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';
ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';
CREATE TABLE IF NOT EXISTS zipkin_annotations (
`trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
`trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',
`span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',
`a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',
`a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',
`a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',
`a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',
`endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',
`endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',
`endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',
`endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null'
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';
ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';
ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces';
ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces';
CREATE TABLE IF NOT EXISTS zipkin_dependencies (
`day` DATE NOT NULL,
`parent` VARCHAR(255) NOT NULL,
`child` VARCHAR(255) NOT NULL,
`call_count` BIGINT
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);
微服務啟動檔案新增如下Bean
import org.apache.tomcat.jdbc.pool.DataSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import zipkin.server.EnableZipkinServer;
import zipkin.storage.mysql.MySQLStorage;
@SpringBootApplication
@EnableEurekaClient
@EnableZipkinServer
public class ZipkinApplication {
public static void main(String[] args) {
SpringApplication.run(ZipkinApplication.class, args);
}
@Bean
public MySQLStorage mySQLStorage(DataSource datasource) {
return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build();
}
}
注:網上的教程裡引入的DataSource是javax.sql.DataSource,但是我引入這個包出現了Could not autowire. There is more than one bean of 'DataSource' type的錯誤,所以我換成了org.apache.tomcat.jdbc.pool.DataSource,目前沒有出現問題。如果有小夥伴出現了異常後果歡迎留言討論 ╮(╯▽╰)╭
小白所學尚淺,文章內容是根據參考+實踐理解所得,如果有錯誤的地方歡迎指正!
相關推薦
從零開始:zipkin
一、工作環境 作業系統:Ubuntu 16.04 java環境:JDK 1.8 SpringBoot版本:1.5.13 SpringCloud版本:Edgware.SR3 二、專案配置 1. zipkin Server pom.xml <depend
從零開始:教你如何訓練神經網路
原文連結 :https://zhuanlan.zhihu.com/p/31953880 選自TowardsDataScience 作者:Vitaly Bushaev 機器之心編譯 作者從神經網路簡單的數學定義開始,沿著損失函式、啟用函式和反向傳播等方法進一步描述基本的優化演算法。在
Python3爬蟲從零開始:環境配置
話不多說,關於爬蟲的作用和介紹網上資料很多,不再累述。 “工欲善其事必先利其器”。 1.首先到Python官網進行Python安裝: 2.環境變數配置: (1)找到Python3安裝路徑,我的如下:C:\Users\Administrator\AppData\
Python3爬蟲從零開始:庫的安裝
抓取網頁之後下一步就是從網頁中提取資訊。提取方式有很多種,可以利用正則表示式進行提請,但是相對而言比較麻煩繁瑣。現在有很多強大的解析庫供我們使用,如lxml,Beautiful Soupp,pyquery等。本節對其安裝進行介紹。 lxml的安裝 lxm
Python3爬蟲從零開始:Beautiful Soup的使用
基本用法 例項1: from bs4 import BeautifulSoup html =""" <html><head><title>The Dormouse's story</title></head&g
Scala從零開始:使用Scala IDE for eclipse寫hello world
雖然Scala是一門比較新的語言,但是很多機構都為其開發了IDE或者整合外掛,比較流行的有Eclipse、IntelliJ以及Netbeans。今天我們使用集成了Scala IDE外掛的Eclipse進行程式碼的編寫。 IDE下載及安裝 大資料學習的順序: (1)大資料的第一代技術
Scala從零開始:使用Scala IDE寫hello world
簡介 在上一篇文章中,我們闡述了Coursera使用Scala的理由,以及Scala的優缺點。說多不如少練,我們今天就開始練習如何使用Scala程式設計。 雖然Scala是一門比較新的語言,但是很多機構都為其開發了IDE或者整合外掛,比較流行的有Eclipse、Intell
從零開始: Spring Cloud微框架系列:spring boot
Spring 頂級專案,包含眾多,我們重點學習一下,SpringCloud專案以及SpringBoot專案 ————————————————————main———————————————————— 一、SpringCloud專案簡介 Spring Cloud:
從零開始:一個正式的vue+webpack專案的目錄結構是怎麼形成的
如何從零開始一個vue+webpack前端工程工作流的搭建,首先我們先從專案的目錄結構入手。一個持續可發展,不斷加入新功能,方便後期維護的目錄結構究竟是長什麼樣子的?接下來閏土大叔帶你們一起手摸手學起來。初級前端初始化目錄篇專案伊始,我們肯定是先在terminal終端命令列(以下簡稱terminal)cd進入
從零開始:用Python搭建神經網路
在這篇部落格裡,我們將從零開始搭建一個三層的神經網路。我們不會對用到的數學原理一一贅述,但我保證你可以直觀地瞭解到我們在做什麼。另外,你也可以通過文章內的連結來獲取更詳細的資訊。 這兒我就假定你已經熟悉基礎的微積分和機器學習的一些概念,比如分類和規範化,最好還能懂得一些優
【轉】Scala從零開始:使用Intellij IDEA寫hello world
在之前的文章中,我們介紹瞭如何使用Scala IDE也就是eclipse中整合的Scala開發外掛來進行Scala語言程式的開發,在使用了一段時間之後,發現eclipse對Scala的支援並不是很好。使用者體驗比較差,比如聯想速度比較慢等。由於在公司一直使用的Scala開發工具是Intellij IDEA(
教程 | 一步步從零開始:使用PyCharm和SSH搭建遠端TensorFlow開發環境
作者:Erik Hallström 機器之心編譯 參與:機器之心編輯部 一般而言,大型的神經網路對硬體能力有著較高的需求——往往需要強勁的 GPU 來加速計算。但是你也許還是想拿著一臺筆記本坐在咖啡店裡安靜地寫 TensorFlow 程式碼,同時還能享受每秒數萬億次
odoo12從零開始:二、個性化定製odoo12 之 建立資料庫頁面
劇情回顧 上一文章,我們已經成功運行了odoo12,並訪問localhost:8069看到如下介面: 我們還沒有建立資料庫,但是我們發現,資料庫管理頁面的logo是odoo,資料庫頁面全是英文的,對於我們國內使用者來說,這是不太友好的。我們想要自定義這個資料庫頁面,有沒有辦法?答案是肯
odoo12從零開始:三、1)建立你的第一個應用模型(module)
前言 以前,我一直都不知道為什麼好多框架的入門都是“hello world”開始,當我思前想後我要如何介紹odoo的model、record、template等繼承等高階特性時,發現在那之前便需要清楚地介紹什麼是模型(model),什麼是記錄
odoo12從零開始:一、安裝odoo執行環境(windows10)
前言 鑑於好多朋友說沒有mac電腦,windows開發其實也差不了多遠,只是個人習慣問題,而且吧,windows的電腦其實配環境也挺快的其實,我在這裡再稍微補一個比較簡單的windows環境部署,希望可以對朋友們有一些幫助。 在windows10上安裝odoo12
odoo12從零開始:三、2)odoo模型層
前言 上一篇文章(建立你的第一個應用模組(module))已經大致描述了odoo的模型層(model)和檢視層(view),這一篇文章,我們將系統地介紹有關於model的知識,其中包括: 1、模型的型別:Model、TransientModel、AbstractModel 2、模型的屬性:_na
從零開始學習iOS開發1:認識xcode
連接 啟動圖標 主動 認識 tor 音樂 滴滴打車 啟動 and 在開始之前還是不得不提一下iPhone應用開發的工具,我當然之前是沒接觸過iPhone開發,也沒使用過apple的不論什麽一種設備。所以我的概念中僅僅知道xcode是最專業的iOS開發工具。如今它是免費
[Golang] 從零開始寫Socket Server(3): 對長、短連接的處理策略(模擬心跳)
microsoft ted 每次 range 點擊 關閉 ade 而在 href 通過前兩章,我們成功是寫出了一套湊合能用的Server和Client,並在二者之間實現了通過協議交流。這麽一來,一個簡易的socket通訊框架已經初具雛形了,那麽我們接下來做的
《從零開始學Swift》學習筆記(Day 57)——Swift編碼規範之凝視規範:文件凝視、文檔凝視、代碼凝視、使用地標凝視
精品 -type mil 顯示 clas ber ansi tex text 原創文章。歡迎轉載。轉載請註明:關東升的博客 前面說到Swift凝視的語法有兩種:單行凝視(//)和多行凝視(/*...*/)。這裏來介紹一下他們的使用規範。 1、文件凝視文件凝視就在每個文
Python爬蟲系列(一):從零開始,安裝環境
tar 公司 pip nal 網頁 解析 目標 http caption 在上一個系列,我們學會使用rabbitmq。本來接著是把公司的celery分享出來,但是定睛一看,celery4.0已經不再支持Windows。公司也逐步放棄了服役多年的celery項目。恰好,公司找