skywalking python
从我开始用就一直更新参考:http://www.iocoder.cn/SkyWalking/install/?vip#
以前一直用的是,而且没有剖析的功能,只能适合服务间的监控。
from skywalking import agent, config config.init(SomeConfig) agent.start()
最近发现skywalking的agent,很牛逼,本来是不想专门写个文档的。
1、前置条件
- python >= 3.7 skywalking >= 8.0
2、一些文档
- https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/
- https://github.com/apache/skywalking-python/blob/master/docs/en/setup/Installation.md#from-pypi
- https://github.com/apache/skywalking-python/blob/master/docs/en/setup/Configuration.md
3、开始装sky和agent
4、python测试代码
import time def method1(): time.sleep(0.02) return '1' def method2(): time.sleep(0.02) return method1() def method3(): time.sleep(0.02) return method2() if __name__ == '__main__': import socketserver from http.server import BaseHTTPRequestHandler class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_POST(self): method3() time.sleep(0.5) self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() self.wfile.write('{"song": "Despacito", "artist": "Luis Fonsi"}'.encode('ascii')) PORT = 19090 Handler = SimpleHTTPRequestHandler with socketserver.TCPServer(("", PORT), Handler) as httpd: httpd.serve_forever()
模拟请求:curl -X POST http://localhost:19090/
5、创建剖析任务
然后分析: