Sentry的使用相关调研

来源:互联网 发布:如何保存淘宝视频 编辑:程序博客网 时间:2024/06/10 07:11

sentry的github地址:https://github.com/getsentry/sentry


sentry官方doc QuickStart地址:http://sentry.readthedocs.org/en/latest/quickstart/

http://blog.shanbay.com/archives/998这里是部署sentry以及在django项目中添加添加sentry日志管理的具体方法。

https://github.com/mdgart/sentrylogs 这里是可以将nginx的错误日志发送到sentry中一并监控管理的工具

uwsgi的日志暂时还没找到怎么用sentry来监控,不过在github上找到了另一个工具用来监控uwsgi日志的,https://github.com/piglei/uwsgi-sloth/ 不过它对uwsgi的日志格式要求有局限性。


pip安装sentry时,关于依赖包有几个坑:

celery安装3.0.25,我们是3.1.9

Django安装1.5.8,我们是1.6.2

Redis安装2.8.0 ,我们是2.9.1

South安装0.8.2 ,我们是0.8.4

kombu安装2.5.16, ,我们是3.0.13

amqp安装1.0.13 ,我们是1.4.4

billiard安装2.7.3.34 ,我们是3.3.0.16


由于涉及到我们的程序使用到的库的不同版本太多,具体风险未知,所以感觉得谨慎一点。。


具体步骤,可以直接按照这个收集整理后的方法来:

  1. $ pip install sentry      <会自动安装所有依赖,包括Django等,耗时久>
  2. $ sentry init         <此时生成~/.sentry/sentry.conf.py配置文件>
  3. $ sentry createsuperuser          <此时创建超级管理员>
  4. $ vim ~/.sentry/sentry.conf.py   <编辑各种配置参数,里面有非常详细的配置说明,可以不用看官网了>
  5. $ sentry start      <运行服务器,若用supervisor运行配置文件参见http://sentry.readthedocs.org/en/latest/quickstart/#configure-supervisord>
  6. 浏览器访问127.0.0.1:9000,访问网页,用superuser账号登陆,会提示创建项目创建工程,选择Django后,界面自动提示,需要添加在Django的settings文件中的两个设置项,然后基本上就大功告成。

关于将nginx的日志发送到sentry的方法:

在安装sentry并运行后,就非常简单了,见https://github.com/mdgart/sentrylogs页面的介绍,

  1. $ pip install sentrylogs
  2. $ sentrylogs --daemonize --sentrydsn "http://2c0d670b03514dd4a89ecd91a3a2e7c0:d31dbaf06f66419c914d41ba7b3ebd46@127.0.0.1/2"     <这个dsn的值可以在sentry网页上找到><此时将会后台守护程序的形式运行,默认读取/var/log/nginx/error.log这个错误日志。>

uwsgi日志分析,网上没有找到怎样集成到sentry,不过有uwsgi-sloth这个国人开源项目,不知是否采用:

github地址:https://github.com/piglei/uwsgi-sloth/

项目详细介绍:http://www.zlovezl.cn/articles/introduction-of-uwsgi-sloth/

运行demo效果查看:http://uwsgi-sloth.zlovezl.cn/

纯python,非Django程序如何发日志给sentry?

Django发送日志给sentry其实就是借助raven来实现的,安装sentry时自动安装raven,如果是纯python,在程序中import raven,然后应该也可以发送。

from raven import Clientclient = Client(dsn='https://public_key:secret_key@sentry.local/project_id')try:   1/0except ZeroDivisionError:   ident = client.get_ident(client.captureException())   print "Exception caught; reference is %s" % ident


0 0