当前位置:网站首页>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
边栏推荐
猜你喜欢
Two tips for pycharm to open multiple projects
Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
Elastic APM安装和使用
Matlab 绘制阴影误差图
Study notes of dataX
Innovus卡住,提示X Error:
堆外内存的使用
【Mysql】redo log,undo log 和binlog详解(四)
Node-v download and application, ES6 module import and export
十大蓝筹NFT近半年数据横向对比
随机推荐
【Mysql】认识Mysql重要架构(一)
Redis principle and usage - installation and distributed configuration
[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi
Nuxt - 项目打包部署及上线到服务器流程(SSR 服务端渲染)
Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
JS - DataTables 关于每页显示数的控制
堆外内存的使用
Server memory failure prediction can actually do this!
服务器内存故障预测居然可以这样做!
Apple generated and verified tokens for PHP
Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points
Hbuilderx runs the wechat developer tool "fail to open ide" to solve the error
JVM command induction
谷粒学院的全部学习源码
十大蓝筹NFT近半年数据横向对比
Study notes of automatic control principle -- correction and synthesis of automatic control system
Li Mu D2L (VI) -- model selection
codeforces dp合集
187. Repeated DNA sequence
【无标题】