102.skywalking使用
# 01.skywalking-python
# 1.0 参考
官网:https://skywalking.apache.org/docs/skywalking-python/v0.7.0/en/setup/intrusive/
包官网:https://pypi.org/project/apache-skywalking/
GitHub:https://github.com/apache/skywalking-python/tree/1d25b08c5a3d6b16719966406fec2c51291b0126
博客案例:https://blog.csdn.net/qq_30355341/article/details/114641498
flask使用skywalking:https://blog.csdn.net/qq_30355341/article/details/114641498
1
2
3
4
5
2
3
4
5
# 1.1 安装
- https://skywalking.apache.org/docs/skywalking-python/v0.7.0/en/setup/installation/
# Install the latest version, using the default gRPC protocol to report data to OAP
pip install "apache-skywalking"
# Install the latest version, using the http protocol to report data to OAP
pip install "apache-skywalking[http]"
# Install the latest version, using the kafka protocol to report data to OAP
pip install "apache-skywalking[kafka]"
# Install a specific version x.y.z
# pip install apache-skywalking==x.y.z
pip install apache-skywalking==0.1.0 # For example, install version 0.1.0 no matter what the latest version is
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 1.2 使用测试
- 只需在启动前初始化 skywalking的配置文件
- 官方文档:https://pypi.org/project/apache-skywalking/
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
from flask import request
from skywalking import agent, config
config.init(collector_address='192.168.56.65:11800', service_name='flask_test02')
agent.start()
agent.start()
app=Flask(__name__)
@app.route('/user/<name>') #设置url传参数 http://127.0.0.1:5000/user/zhangsan?name=aaa
def first_flask(name): #视图必须有对应接收参数
print(name) # zhangsan
print(request.form) # 获取post请求
print(request.values.get('name')) # 获取get请求中参数
print(request.args.get('name')) # 获取get请求中参数
return 'Hello World'
if __name__ == '__main__':
app.run(debug=True,port=8001)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
上次更新: 2024/3/13 15:35:10