当前位置:网站首页>Zipkin installation and use
Zipkin installation and use
2022-07-26 09:16:00 【Or turn around】
In front of blog Introduced in apm Principles and open source apm frame , Here we continue to introduce Zipkin Installation and use .
Zipkin Official website :https://zipkin.io/pages/quickstart.
Navigation before :
Selection and practice of distributed tracking system
Elastic APM Installation and use
Cat Installation and use
Zipkin Server deployment
According to the official website document , There are two ways to deploy the server :
1.Java8 And above , You can download the official package directly to run :
curl -sSL https://zipkin.io/quickstart.sh | bash -s
java -jar zipkin.jar
2. Download the source code and package it yourself
# get the latest source
git clone https://github.com/openzipkin/zipkin
cd zipkin
# Build the server and also make its dependencies
./mvnw -DskipTests --also-make -pl zipkin-server clean install
# Run the server
java -jar ./zipkin-server/target/zipkin-server-*exec.jar
The official package downloaded by bloggers will report an error after running , So run in the second way zipkin Server side .
Zipkin Use
Officially supported clients :
There are more clients supported by the community , Almost all mainstream languages support , See the official website for details :
https://zipkin.io/pages/tracers_instrumentation.html.
Let's say python For example, . The environment is :python2.7, Use py_zipkin library .
Create the first service :
import time
import requests
from flask import Flask
from flask import request
from py_zipkin.zipkin import zipkin_span, create_http_headers_for_new_span, ZipkinAttrs
app = Flask(__name__)
app.config.update({
"ZIPKIN_HOST": "127.0.0.1",
"ZIPKIN_PORT": "9411",
"APP_PORT": 5000,
})
def do_stuff():
time.sleep(0.5)
headers = create_http_headers_for_new_span()
requests.get('http://localhost:8000/service1/', headers=headers)
return 'OK'
def http_transport(encoded_span):
# encoding prefix explained in https://github.com/Yelp/py_zipkin#transport
# body = b"\x0c\x00\x00\x00\x01"+encoded_span
body = encoded_span
zipkin_url = "http://127.0.0.1:9411/api/v1/spans"
# zipkin_url = "http://{host}:{port}/api/v1/spans".format(
# host=app.config["ZIPKIN_HOST"], port=app.config["ZIPKIN_PORT"])
headers = {"Content-Type": "application/x-thrift"}
# You'd probably want to wrap this in a try/except in case POSTing fails
r = requests.post(zipkin_url, data=body, headers=headers)
print(type(encoded_span))
print(encoded_span)
print(body)
print(r)
print(r.content)
@app.route('/')
def index():
with zipkin_span(
service_name="webapp",
zipkin_attrs=ZipkinAttrs(
trace_id=request.headers.get('X-B3-TraceID', None),
span_id=request.headers.get('X-B3-SpanID', None),
parent_span_id=request.headers.get('X-B3-ParentSpanID', None),
flags=request.headers.get('X-B3-Flags', None),
is_sampled=request.headers.get('X-B3-Sampled', None),
),
span_name='index',
transport_handler=http_transport,
port=5000,
sample_rate=100, # 0.05, # Value between 0.0 and 100.0
) as zipkin_context:
with zipkin_span(service_name="webapp", span_name='do_stuff'):
do_stuff()
print zipkin_context.zipkin_attrs.trace_id
time.sleep(1)
return 'OK', 200
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, debug=True)
Create a second service :
# coding=utf-8
import time
import requests
from flask import Flask
from flask import request
from py_zipkin.zipkin import zipkin_span, ZipkinAttrs
app = Flask(__name__)
app.config.update({
"ZIPKIN_HOST": "127.0.0.1",
"ZIPKIN_PORT": "9411",
"APP_PORT": 8000,
})
def do_stuff():
time.sleep(0.5)
with zipkin_span(service_name="service1", span_name='service1_db_search'):
db_search()
return 'OK'
def db_search():
time.sleep(2)
def http_transport(encoded_span):
# encoding prefix explained in https://github.com/Yelp/py_zipkin#transport
# body = b"\x0c\x00\x00\x00\x01" + encoded_span
body = encoded_span
zipkin_url = "http://127.0.0.1:9411/api/v1/spans"
# zipkin_url = "http://{host}:{port}/api/v1/spans".format(
# host=app.config["ZIPKIN_HOST"], port=app.config["ZIPKIN_PORT"])
headers = {"Content-Type": "application/x-thrift"}
# You'd probably want to wrap this in a try/except in case POSTing fails
requests.post(zipkin_url, data=body, headers=headers)
@app.route('/service1/')
def index():
with zipkin_span(
service_name="service1",
zipkin_attrs=ZipkinAttrs(
trace_id=request.headers.get('X-B3-TraceID', None),
span_id=request.headers.get('X-B3-SpanID', None),
parent_span_id=request.headers.get('X-B3-ParentSpanID', None),
flags=request.headers.get('X-B3-Flags', None),
is_sampled=request.headers.get('X-B3-Sampled', None),
),
span_name='index_service1',
transport_handler=http_transport,
port=8000,
sample_rate=100, # 0.05, # Value between 0.0 and 100.0
) as zipkin_context:
with zipkin_span(service_name="service1", span_name='service1_do_stuff'):
do_stuff()
print zipkin_context.zipkin_attrs.trace_id
return 'OK', 200
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000, debug=True)
visit http://127.0.0.1:5000/, Then login zikin backstage http://127.0.0.1:9411/ You can see the following interface :

Click the search button , You can see the call information :
Click on show Entering the call link, you can see the message tree :
Be careful :zipkin Version must be py_zipkin==0.20.0(ubuntu+python2.7), When using 0.20.1 when , Some service names are displayed as UNKNOWN:
Zipkin storage
According to the deployment above ,zipkin The data of is stored in memory by default . Data will be lost when the service is restarted . Next, change the storage mode to mysql.
newly build zipkin database , In source code zipkin-storage/mysql-v1/src/main/resources In the directory sql Script (https://github.com/openzipkin/zipkin/blob/master/zipkin-storage/mysql-v1/src/main/resources/mysql.sql), perform sql The script creates the data table .
start-up zipkin Specify database parameters on the server :
STORAGE_TYPE=mysql MYSQL_USER=root MYSQL_PASS=123456 MYSQL_HOST=127.0.0.1 MYSQL_TCP_PORT=3306 java -jar zipkin-server-*exec.jar
In this way, the buried point data will be stored in the database .zipkin_spans The data are as follows :
Reference material :
[1]https://zipkin.io/
[2]https://www.cnblogs.com/xiao987334176/p/12074335.html
边栏推荐
- redis原理和使用-安装和分布式配置
- The essence of attack and defense strategy behind the noun of network security
- PHP 之 Apple生成和验证令牌
- (2006,Mysql Server has gone away)问题处理
- Laravel框架日志文件存放在哪里?怎么用?
- 对象型的集合按某个属性的值进行去重
- Cat安装和使用
- JS - DataTables control on the number of displays per page
- 【ARKit、RealityKit】把图片转为3D模型
- Error: Cannot find module ‘umi‘ 问题处理
猜你喜欢

Uploading pictures on Alibaba cloud OSS

Flask project learning (I) -- sayhello

Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points

NTT (fast number theory transformation) polynomial inverse 1500 word analysis

ES6 modular import and export) (realize page nesting)

2022流动式起重机司机考试题模拟考试题库模拟考试平台操作
![[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi](/img/39/135d29dae23b55497728233f31aa6a.png)
[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi

Li Mu D2L (IV) -- softmax regression

(2006,Mysql Server has gone away)问题处理

CF1481C Fence Painting
随机推荐
Pat grade a a1076 forwards on Weibo
Apple generated and verified tokens for PHP
Grain College of all learning source code
Day06 homework - skill question 7
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
ONTAP 9文件系统的限制
Clean the label folder
Uploading pictures on Alibaba cloud OSS
756. Serpentine matrix
Processing of inconsistent week values obtained by PHP and MySQL
PAT 甲级 A1034 Head of a Gang
对象型的集合按某个属性的值进行去重
服务器内存故障预测居然可以这样做!
【线上死锁分析】由index_merge引发的死锁事件
Unity topdown character movement control
839. Simulation reactor
Matlab 绘制阴影误差图
Use of off heap memory
Li Mu D2L (VI) -- model selection
Go intelligent robot alpha dog, alpha dog robot go