python的版本的3.5
uwsgi是2.0.14,要配置日志请求分析器
参考博客:http://ju.outofmemory.cn/entry/82079
参考github:https://github.com/piglei/uwsgi-sloth/
https://github.com/piglei/uwsgi-sloth/raw/master/uwsgi-sloth-screenshot.png
快速开始
安装
uwsgi-sloth完全使用python编写,你可以直接使用pip来安装它:
# 安装pypi的稳定版本$ pip install uwsgi-sloth# 安装github上的最新版$ pip install -e git+https://github.com/piglei/uwsgi-sloth#egg=uwsgi-sloth
生成一份静态报表文件
安装完成后,你可以使用 uwsgi-sloth analyze 命令来分析你的uwsgi日志文件。
# Generate a report$ uwsgi-sloth analyze -f uwsgi_access.log --output=report.html# Specify threshold for request process time$ uwsgi-sloth analyze -f uwsgi_access.log --output=report.html --min-msecs=400
查看更多: uwsgi-sloth analyze
实时报表
我们还提供了一个更强大的功能:实时日志报表,这个配置起来比上一个要稍微麻烦一些。
首先,通过 uwsgi-sloth echo_conf 命令创建一个默认的配置文件:
uwsgi-sloth echo_conf > /data/uwsgi_sloth/myblog.conf
默认的配置文件看起来是这样的,每一个选项描述写在了注释里:
# A sample uwsgi-sloth config file# uwsgi log path, only support default log formatuwsgi_log_path = '/your_uwsgi_logs/web.log'# All HTML files and data files will store here, must have read/write permissionsdata_dir = '/you_data/uwsgi-sloth/'# Minimal msecs for detect slow requests, default to 200# min_msecs = 200# Domain for your website, best givendomain = 'http://www.yourwebsite.com/'# Custom url regular expressions file# url_file = '/your_custom_url_file_path'
在修改了最重要的 uwsgi_log_path 和 data_dir 两个参数之后,你便可以通过uwsgi-sloth start -c /data/uwsgi_sloth/myblog.conf 命令来启动uwsgi-sloth的worker了,如果 一切都正常的话,你会看到这样的输出:
[2014-06-26 01:32:56,851] uwsgi_sloth INFO: Start from last savepoint, last_log_datetime: 2014-06-26 09:32:04[2014-06-26 01:32:58,859] uwsgi_sloth INFO: Rendering HTML file /data/uwsgi_sloth/myblog/html/latest_5mins.html...... ...
如果你的日志文件比较庞大,第一次启动可能会花上比较长的时间。
作为守护进程运行
uwsgi-sloth 并没有内置作为守护进程启动的选项,我建议你使用类似 supervisor这样的工具来管理uwsgi-sloth进程。
查看你的实时报表
现在,实时的报表已经被建立而且可以自动更新了,我们应该配置我们的服务器来访问它, 下面这个配置是针对Nginx的:
$ cat /etc/nginx/sites-enabled/sloth_myblog.conf server { listen 80; server_name uwsgi-sloth.zlovezl.cn; location / { root /data/uwsgi_sloth/myblog/html/; index "latest_5mins.html"; }}
重载了Nginx的配置文件以后,打开你的浏览器你就能看到那些漂亮的报表了。
当前命令
uwsgi-sloth analyze
可用参数
usage: uwsgi-sloth analyze [-h] -f FILEPATH [--output OUTPUT] [--min-msecs MIN_MSECS] [--domain DOMAIN] [--url-file URL_FILE]optional arguments: -h, --help show this help message and exit -f FILEPATH, --filepath FILEPATH Path of uwsgi log file --output OUTPUT HTML report file path --min-msecs MIN_MSECS Request serve time lower than this value will not be counted, default: 200 --domain DOMAIN Make url in report become a hyper-link by settings a domain --url-file URL_FILE Customized url rules in regular expression
使用一个自定义的URL规则文件
默认情况下,uwsgi-sloth会通过把URL中连续的数字转换为“d+”这样的符号来给URL 分组,如果你需要自定义你的URL规则,你需要建立一个URL规则文件,内容大概是这样:
$ cat url_rules# A valid url_rules file are seperated regular expressions^club/(?P<place>\w+)/(?P<year>\d+)/(?P<issue>\d+)/signup/$^club/signup/success/$^club/checkin/success/$
然后使用--url-file选项来指定它
$ uwsgi-sloth analyze -f uwsgi_access.log --output=report.html --url-file=url_rules
uwsgi-sloth echo_conf
打印一个默认的配置文件
uwsgi-sloth start
启动实时报表的worker
$ uwsgi-sloth start -h usage: uwsgi-sloth start [-h] -c CONFIG optional arguments: -h, --help show this help message and exit -c CONFIG, --config CONFIG uwsgi-sloth config file, use "uwsgi-sloth echo_conf" for a default one
错误处理:运行的时候报了类型错误,说在model,py的43行,类型错误
解决:在43行前边加一行:fp=fp.encode()
文章评论
发布于 2019-02-28 14:10:54 回复