Graphite监控scrapy
在写爬虫项目的时候遇到的需求是对爬虫进行监控,分析爬虫的性能,将其可视化。通过查找资料我发现graphite可以实现。graphite是一个性能监控的工具。
本文将介绍如何利用graphite监控scrapy。
我参考的资料如下:
http://www.open-open.com/lib/view/open1419683400953.html
http://tripleday.cn/2016/10/06/graphite/
下面简单介绍一下graphite的安装和使用,如有不明白之处可以参照上面的链接中的文章
步骤1:安装graphite
在安装的过程中你可能会遇到安装graphite-web后缺少manage.py
解决办法:
从 https://github.com/graphite-project/graphite-web.git下载graphite-web,将其中的manage.py拷贝到/opt/graphite/webapp下
步骤2:配置graphite
.graphite会自动安装在/opt/graphite目录下
将/opt/graphite/conf下的*.example去掉.example后缀
2.将/opt/graphite/webapp/graphite/local_settings.py文件里的TIME_ZONE配置改成如下:
3.在配置文件storage-aggregation.conf里添加
[scrapy_min]
pattern = ^scrapy\..*_min$
xFilesFactor = 0.1
aggregationMethod = min
[scrapy_max]
pattern = ^scrapy\..*_max$
xFilesFactor = 0.1
aggregationMethod = max
[scrapy_sum]
pattern = ^scrapy\..*_count$
xFilesFactor = 0.1
aggregationMethod = sum
步骤4:配置scrapy的setting.py
STATS_CLASS ='scrapygraphite.GraphiteStatsCollector'
GRAPHITE_HOST = '127.0.0.1'
GRAPHITE_PORT = 2003
步骤5.启动graphite
启动carbon,carbon会在默认的2003端口接收数据。
python /opt/graphite/bin/carbon-cache.py start |
启动django,即整个Graphite的web应用。
python /opt/graphite/webapp/graphite/manage.py runserver
启动之后对数据库进行同步可能会出现报错:no such table:account_profile
解决办法:
使用 python manage.py migrate --run-syncdb 命令进行同步
之后用浏览器访问将看到一下界面
步骤6.启动redis
步骤7:启动scrapy
问题8:在graphite上查看scrapy
刷新浏览器页面进入如下目录就可看到scrapy运行情况