首页 > 编程语言 >skywalking 实现收集基于python的Django项目链路追踪案例

skywalking 实现收集基于python的Django项目链路追踪案例

时间:2022-10-04 12:22:51浏览次数:89  
标签:python MainThread sw Django failed WARNING install skywalking

一、python3环境设置

1.1、安装python3

apt-get update
apt install python3-pip -y
pip install "apache-skywalking"
[root@skywalking-agent-07 ~]# pip install "apache-skywalking"

Collecting apache-skywalking
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7f29f5b41880>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/3f/2a/8934d1a7d781ec3c16114bad1bc5376bcf506e261c42c6b6718c0418e5a9/apache_skywalking-0.8.0-py3-none-any.whl
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7f29f5b41910>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/3f/2a/8934d1a7d781ec3c16114bad1bc5376bcf506e261c42c6b6718c0418e5a9/apache_skywalking-0.8.0-py3-none-any.whl
  Downloading apache_skywalking-0.8.0-py3-none-any.whl (168 kB)
     |████████████████████████████████| 168 kB 670 kB/s 
Collecting packaging
  Downloading packaging-21.3-py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 4.2 MB/s 
Collecting wrapt
  Downloading wrapt-1.14.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81 kB)
     |████████████████████████████████| 81 kB 4.7 MB/s 
Collecting grpcio-tools
  Downloading grpcio_tools-1.49.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB)
     |████████████████████████████████| 2.4 MB 5.0 MB/s 
Collecting grpcio
  Downloading grpcio-1.49.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB)
     |████████████████████████████████| 4.7 MB 41.9 MB/s 
Collecting pyparsing!=3.0.5,>=2.0.2
  Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
     |████████████████████████████████| 98 kB 7.3 MB/s 
Collecting protobuf<5.0dev,>=4.21.3
  Downloading protobuf-4.21.7-cp37-abi3-manylinux2014_x86_64.whl (408 kB)
     |████████████████████████████████| 408 kB 13.8 MB/s 
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from grpcio-tools->apache-skywalking) (45.2.0)
Requirement already satisfied: six>=1.5.2 in /usr/lib/python3/dist-packages (from grpcio->apache-skywalking) (1.14.0)
Installing collected packages: pyparsing, packaging, wrapt, protobuf, grpcio, grpcio-tools, apache-skywalking
Successfully installed apache-skywalking-0.8.0 grpcio-1.49.1 grpcio-tools-1.49.1 packaging-21.3 protobuf-4.21.7 pyparsing-3.0.9 wrapt-1.14.1

1.2、导入模块,验证当前环境是否能正常注册到skywalking server

[root@skywalking-agent-07 ~]# python3

Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from skywalking import agent, config
>>> config.init(collector_address='172.16.88.187:11800', service_name='python-app')
>>> agent.start()
skywalking [MainThread] [WARNING] plugin sw_aiohttp failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_bottle failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_celery failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_django failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_elasticsearch failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_falcon failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_fastapi failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_flask failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_kafka failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_mysqlclient failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_psycopg failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_psycopg2 failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_pymongo failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_pymysql failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_pyramid failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_rabbitmq failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_redis failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_sanic failed to install, please disregard this warning if the corresponding package was not used in your project
skywalking [MainThread] [WARNING] plugin sw_tornado failed to install, please disregard this warning if the corresponding package was not used in your project
>>> 
>>> exit()
[root@skywalking-agent-07 ~]#

二、上传并部署django项目

2.1、上传项目并安装依赖包

[root@skywalking-agent-07 ~]# tar -xf django-test.tgz

[root@skywalking-agent-07 ~]# cd django-test/
[root@skywalking-agent-07 django-test]# ls
bin  include  lib  mysite  pyvenv.cfg  requirements.txt
[root@skywalking-agent-07 django-test]# cat requirements.txt 
apache-skywalking==0.7.0
asgiref==3.4.1
backports.zoneinfo==0.2.1
Django==4.0.1
grpcio==1.43.0
grpcio-tools==1.43.0
packaging==21.3
protobuf==3.19.3
PyMySQL==1.0.2
pyparsing==3.0.6
six==1.16.0
sqlparse==0.4.2
wrapt==1.13.3
[root@skywalking-agent-07 django-test]# pip3 install -r requirements.txt   #安装依赖包
Collecting apache-skywalking==0.7.0
  Downloading apache_skywalking-0.7.0-py3-none-any.whl (169 kB)
     |████████████████████████████████| 169 kB 610 kB/s 
Collecting asgiref==3.4.1
  Downloading asgiref-3.4.1-py3-none-any.whl (25 kB)
Collecting backports.zoneinfo==0.2.1
  Downloading backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_x86_64.whl (74 kB)
     |████████████████████████████████| 74 kB 2.5 MB/s 
Collecting Django==4.0.1
  Downloading Django-4.0.1-py3-none-any.whl (8.0 MB)
     |████████████████████████████████| 8.0 MB 4.2 MB/s 
Collecting grpcio==1.43.0
  Downloading grpcio-1.43.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB)
     |████████████████████████████████| 4.1 MB 27.8 MB/s 
Collecting grpcio-tools==1.43.0
  Downloading grpcio_tools-1.43.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB)
     |████████████████████████████████| 2.4 MB 10.4 MB/s 
Requirement already satisfied: packaging==21.3 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 7)) (21.3)
Collecting protobuf==3.19.3
  Downloading protobuf-3.19.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB)
     |████████████████████████████████| 1.1 MB 10.6 MB/s 
Collecting PyMySQL==1.0.2
  Downloading PyMySQL-1.0.2-py3-none-any.whl (43 kB)
     |████████████████████████████████| 43 kB 3.9 MB/s 
Collecting pyparsing==3.0.6
  Downloading pyparsing-3.0.6-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 12.5 MB/s 
Collecting six==1.16.0
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting sqlparse==0.4.2
  Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 2.1 MB/s 
Collecting wrapt==1.13.3
  Downloading wrapt-1.13.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (84 kB)
     |████████████████████████████████| 84 kB 4.7 MB/s 
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from grpcio-tools==1.43.0->-r requirements.txt (line 6)) (45.2.0)
ERROR: launchpadlib 1.10.13 requires testresources, which is not installed.
Installing collected packages: wrapt, six, grpcio, protobuf, grpcio-tools, apache-skywalking, asgiref, backports.zoneinfo, sqlparse, Django, PyMySQL, pyparsing
  Attempting uninstall: wrapt
    Found existing installation: wrapt 1.14.1
    Uninstalling wrapt-1.14.1:
      Successfully uninstalled wrapt-1.14.1
  Attempting uninstall: six
    Found existing installation: six 1.14.0
    Not uninstalling six at /usr/lib/python3/dist-packages, outside environment /usr
    Can't uninstall 'six'. No files were found to uninstall.
  Attempting uninstall: grpcio
    Found existing installation: grpcio 1.49.1
    Uninstalling grpcio-1.49.1:
      Successfully uninstalled grpcio-1.49.1
  Attempting uninstall: protobuf
    Found existing installation: protobuf 4.21.7
    Uninstalling protobuf-4.21.7:
      Successfully uninstalled protobuf-4.21.7
  Attempting uninstall: grpcio-tools
    Found existing installation: grpcio-tools 1.49.1
    Uninstalling grpcio-tools-1.49.1:
      Successfully uninstalled grpcio-tools-1.49.1
  Attempting uninstall: apache-skywalking
    Found existing installation: apache-skywalking 0.8.0
    Uninstalling apache-skywalking-0.8.0:
      Successfully uninstalled apache-skywalking-0.8.0
  Attempting uninstall: pyparsing
    Found existing installation: pyparsing 3.0.9
    Uninstalling pyparsing-3.0.9:
      Successfully uninstalled pyparsing-3.0.9
Successfully installed Django-4.0.1 PyMySQL-1.0.2 apache-skywalking-0.7.0 asgiref-3.4.1 backports.zoneinfo-0.2.1 grpcio-1.43.0 grpcio-tools-1.43.0 protobuf-3.19.3 pyparsing-3.0.6 six-1.16.0 sqlparse-0.4.2 wrapt-1.13.3
[root@skywalking-agent-07 django-test]# pip3 install -r requirements.txt #再次确认是否遗漏少装
Requirement already satisfied: apache-skywalking==0.7.0 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 1)) (0.7.0)
Requirement already satisfied: asgiref==3.4.1 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 2)) (3.4.1)
Requirement already satisfied: backports.zoneinfo==0.2.1 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 3)) (0.2.1)
Requirement already satisfied: Django==4.0.1 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 4)) (4.0.1)
Requirement already satisfied: grpcio==1.43.0 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 5)) (1.43.0)
Requirement already satisfied: grpcio-tools==1.43.0 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 6)) (1.43.0)
Requirement already satisfied: packaging==21.3 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 7)) (21.3)
Requirement already satisfied: protobuf==3.19.3 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 8)) (3.19.3)
Requirement already satisfied: PyMySQL==1.0.2 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 9)) (1.0.2)
Requirement already satisfied: pyparsing==3.0.6 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 10)) (3.0.6)
Requirement already satisfied: six==1.16.0 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 11)) (1.16.0)
Requirement already satisfied: sqlparse==0.4.2 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 12)) (0.4.2)
Requirement already satisfied: wrapt==1.13.3 in /usr/local/lib/python3.8/dist-packages (from -r requirements.txt (line 13)) (1.13.3)
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from grpcio-tools==1.43.0->-r requirements.txt (line 6)) (45.2.0)
[root@skywalking-agent-07 django-test]# 

2.2、创建django项目mysite

[root@skywalking-agent-07 django-test]# rm -fr mysite/
[root@skywalking-agent-07 django-test]# django-admin startproject mysite

2.3、创建应用

[root@skywalking-agent-07 django-test]# cd mysite/
[root@skywalking-agent-07 mysite]# python3 manage.py startapp myapp

2.4、初始化数据库

[root@skywalking-agent-07 mysite]# python3 manage.py makemigrations
[root@skywalking-agent-07 mysite]# python3 manage.py migrate

2.5、创建管理员, 用于登录

[root@skywalking-agent-07 mysite]# python3 manage.py createsuperuser

[root@skywalking-agent-07 mysite]# python3 manage.py createsuperuser
Username (leave blank to use 'root'): root
Email address: [email protected]
Password: 
Password (again): 
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
[root@skywalking-agent-07 mysite]# 

用户密码:root  1qaz@WSX

2.6、运行项目

设置相关环境变量
[root@skywalking-agent-07 mysite]# export SW_AGENT_NAME='python-app1'
[root@skywalking-agent-07 mysite]# export SW_AGENT_NAMESPACE='python-app1'
[root@skywalking-agent-07 mysite]# export SW_AGENT_COLLECTOR_BACKEND_SERVICES='172.16.88.187:11800'
[root@skywalking-agent-07 mysite]# vi mysite/settings.py

28    ALLOWED_HOSTS = ['127.0.0.1','172.16.88.194']

启动项目

[root@skywalking-agent-07 mysite]# sw-python -d run python3 manage.py runserver 172.16.88.194:80

skywalking-cli [DEBUG] Args received Namespace(command=['python3', 'manage.py', 'runserver', '172.16.88.194:80'], debug=True, option='run')
skywalking-cli [DEBUG] SkyWalking Python agent with CLI option 'run' and command ['python3', 'manage.py', 'runserver', '172.16.88.194:80']
skywalking-cli [DEBUG] SkyWalking Python agent `runner` received command ['python3', 'manage.py', 'runserver', '172.16.88.194:80']
skywalking-cli [DEBUG] Adding sitecustomize.py to PYTHONPATH
skywalking-cli [DEBUG] Updated PYTHONPATH - /usr/local/lib/python3.8/dist-packages/skywalking/bootstrap/loader
skywalking-cli [DEBUG] New process starting with file - `python3` args - `['python3', 'manage.py', 'runserver', '172.16.88.194:80']`
skywalking-loader [MainThread] [DEBUG] ---------------sitecustomize.py---------------
skywalking-loader [MainThread] [DEBUG] Successfully imported sitecustomize.py from `/usr/local/lib/python3.8/dist-packages/skywalking/bootstrap/loader/sitecustomize.py`
skywalking-loader [MainThread] [DEBUG] You are inside working dir - /root/django-test/mysite
skywalking-loader [MainThread] [DEBUG] Using Python version - 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] 
skywalking-loader [MainThread] [DEBUG] Using executable at - /usr/bin/python3
skywalking-loader [MainThread] [DEBUG] System Base Python executable location /usr
skywalking-loader [MainThread] [DEBUG] Original sitecustomize module not found, skipping.
skywalking-loader [MainThread] [DEBUG] SkyWalking Python Agent starting, loader finished.
skywalking [MainThread] [WARNING] failed to install plugin sw_aiohttp
skywalking [MainThread] [WARNING] failed to install plugin sw_celery
skywalking [MainThread] [WARNING] failed to install plugin sw_elasticsearch
skywalking [MainThread] [WARNING] failed to install plugin sw_falcon
skywalking [MainThread] [WARNING] failed to install plugin sw_flask
skywalking [MainThread] [WARNING] failed to install plugin sw_kafka
skywalking [MainThread] [WARNING] failed to install plugin sw_psycopg2
skywalking [MainThread] [WARNING] failed to install plugin sw_pymongo
skywalking [MainThread] [WARNING] failed to install plugin sw_pyramid
skywalking [MainThread] [WARNING] failed to install plugin sw_rabbitmq
skywalking [MainThread] [WARNING] failed to install plugin sw_redis
skywalking [MainThread] [WARNING] failed to install plugin sw_sanic
skywalking [MainThread] [WARNING] failed to install plugin sw_tornado
skywalking-loader [MainThread] [DEBUG] ---------------sitecustomize.py---------------
skywalking-loader [MainThread] [DEBUG] Successfully imported sitecustomize.py from `/usr/local/lib/python3.8/dist-packages/skywalking/bootstrap/loader/sitecustomize.py`
skywalking-loader [MainThread] [DEBUG] You are inside working dir - /root/django-test/mysite
skywalking-loader [MainThread] [DEBUG] Using Python version - 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] 
skywalking-loader [MainThread] [DEBUG] Using executable at - /usr/bin/python3
skywalking-loader [MainThread] [DEBUG] System Base Python executable location /usr
skywalking-loader [MainThread] [DEBUG] Original sitecustomize module not found, skipping.
skywalking-loader [MainThread] [DEBUG] SkyWalking Python Agent starting, loader finished.
skywalking [MainThread] [WARNING] failed to install plugin sw_aiohttp
skywalking [MainThread] [WARNING] failed to install plugin sw_celery
skywalking [MainThread] [WARNING] failed to install plugin sw_elasticsearch
skywalking [MainThread] [WARNING] failed to install plugin sw_falcon
skywalking [MainThread] [WARNING] failed to install plugin sw_flask
skywalking [MainThread] [WARNING] failed to install plugin sw_kafka
skywalking [MainThread] [WARNING] failed to install plugin sw_psycopg2
skywalking [MainThread] [WARNING] failed to install plugin sw_pymongo
skywalking [MainThread] [WARNING] failed to install plugin sw_pyramid
skywalking [MainThread] [WARNING] failed to install plugin sw_rabbitmq
skywalking [MainThread] [WARNING] failed to install plugin sw_redis
skywalking [MainThread] [WARNING] failed to install plugin sw_sanic
skywalking [MainThread] [WARNING] failed to install plugin sw_tornado
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 04, 2022 - 03:48:47
Django version 4.0.1, using settings 'mysite.settings'
Starting development server at http://172.16.88.194:80/
Quit the server with CONTROL-C.

2.7、检查并验证项目是否正常运行

2.8、验证skywalking server端数据采集

 

标签:python,MainThread,sw,Django,failed,WARNING,install,skywalking
From: https://www.cnblogs.com/cyh00001/p/16753484.html

相关文章

  • 0555-6.1.0-使用Python并发访问认证和非认证集群
    作者:李继武1文档编写目的Fayson在前面的文章《​​0553-6.1.0-如何使用Java代码同时访问安全和非安全CDH集群​​》和《​​0554-6.1.0-同一java进程中同时访问认证和非认证......
  • python在VScode中中文输出乱码的解决方案
    ————————————————版权声明:本文为CSDN博主「Rhett.Yao」的原创文章。原文链接:https://blog.csdn.net/m0_63109538/article/details/126419637——————......
  • python系列教程196——参数匹配
    声明:在人工智能技术教学期间,不少学生向我提一些python相关的问题,所以为了让同学们掌握更多扩展知识更好地理解AI技术,我让助理负责分享这套python系列教程,希望能帮到大家!由于......
  • 【Web开发】Python实现Web服务器(Bottle框架)
    Django-TheWebframeworkforperfectionistswithdeadlines.Flask-ThePythonmicroframeworkforbuildingwebapplications.Tornado-TornadoisaPythonw......
  • Python代码调试方法
    对于每个程序开发者来说,调试几乎是必备技能。常用Pycharm编辑器里的方法有Print大法、log大法,但缺少类似Matlab的变量区,给代码调试带来不便,特别是在有函数的情况下,变量无法......
  • python 批量删除超过某时长的视频 (改)
    importos.pathfrommoviepy.editorimportVideoFileClipfromtqdmimporttqdmdefget_file_names(path):return[os.path.join(path,f)forfinos.listdir(......
  • 配置Django实现数据库读写分离
    配置Django实现数据库读写分离django在进行数据库操作的时候,读取数据与写数据(增、删、改)可以分别从不同的数据库进行操作。1.在配置文件中增加slave数据库的配置DATABA......
  • Django中六个常用的自定义装饰器
    Django中六个常用的自定义装饰器 目录装饰器作用Django装饰器GroupRequiredAnonymousrequiredSuperuserrequiredAjaxrequiredTimeit自定义功能......
  • python partition函数_Python partition()函数的使用方法
    一、partition()函数的语法格式string_name.partition(separator)(1)string_name为要被分隔的字符串或字符串变量。(2)该函数有一个字符串类型的参数:separator,该参数用于指......
  • Django 出现 frame because it set X-Frame-Options to deny 错误
    一、背景使用django3进行开发时,由于项目前端页面使用iframe框架,浏览器错误提示信息如下Refusedtodisplay'http://127.0.0.1:8000/'inaframebecauseitset'X-F......