• 隐藏侧边栏
  • 展开分类目录
  • 关注微信公众号
  • 我的GitHub
  • QQ:1753970025
Chen Jiehua

Sentry日志管理 

目录

Sentry是个很好用的错误日志服务器,可以将程序错误的详细情况集中捕获,并提供一个很漂亮的Web界面来浏览错误。 Sentry本身是用python写的,但它支持python、php、ruby、iOS等多种语言。

Sentry安装

采用Python virtualenv搭建sentry安装环境:

$sudo apt-get install python-dev python-pip
$sudo pip install -U virtualenv
$virtualenv sentry
$source sentry/bin/activate
$pip install -U sentry
#由于sentry依赖的包比较多,安装过程可能会出现缺少某些Linux类库,sudo apt-get install下载安装即可;
#sudo apt-get install libffi-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev
#sentry
usage: [SENTRY_CONF=/path/to/settings.py] sentry [command] [options]

# install sentry and its postgresql dependencies
$pip install -U sentry[postgres]
# or if you choose, mysql. 个人使用情况,习惯采用mysql
$pip install -U sentry[mysql]

#sentry初始化,默认生成配置文件 ~/.sentry/sentry.conf.py
$sentry init

编辑配置文件:

# ~/.sentry/sentry.conf.py

# 配置数据库
# for more information on DATABASES, see the Django configuration at:
# https://docs.djangoproject.com/en/1.6/ref/databases/
DATABASES = {
    'default': {
        # We suggest PostgreSQL for optimal performance
        #'ENGINE': 'sentry.db.postgres',

        # Alternatively you can use MySQL
        'ENGINE': 'django.db.backends.mysql',

        'NAME': 'sentry',
        'USER': 'postgres',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

# No trailing slash!
# 默认为空
SENTRY_URL_PREFIX = ''
# 配置web server
SENTRY_WEB_HOST = '127.0.0.1'
SENTRY_WEB_PORT = 9000
SENTRY_WEB_OPTIONS = {
    'workers': 3,  # the number of gunicorn workers
    'secure_scheme_headers': {'X-FORWARDED-PROTO': 'https'},  # detect HTTPS mode from X-Forwarded-Proto header
}

# 配置redis
SENTRY_REDIS_OPTIONS = {
    'hosts': {
        0: {
            'host': '127.0.0.1',
            'port': 6379,
            'timeout': 3,
            #'password': 'redis auth password'
        }
    }
}

为sentry新建一个数据库,然后继续配置:

$sentry upgrade
# 新建一个用户
$sentry createuser

# 启动Web service
$sentry start
# 启动Workers
$sentry celery worker -B

这样就可以通过浏览器来访问了 http://localhost:9000

 

使用supervisor进行配置:

[program:sentry-web]
directory=/www/sentry/   # 安装目录(virtualenv出来的目录)
command=runinenv /www/sentry sentry start
user=xxx
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=syslog
stderr_logfile=syslog

[program:sentry-worker]
directory=/www/sentry/
command=runinenv /www/sentry sentry celery worker -B
user=xxx
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=syslog
stderr_logfile=syslog

定期清理旧的日志,节约磁盘空间

$crontab -e
0  3  *  *  *  sentry cleanup --day=30

客户端

通过在sentry的后台,新建一个项目后,获取sentry dsn,客户端可以使用raven-go

 

参考:
http://blog.charlee.li/sentry-manage-log/
http://sentry.readthedocs.org/en/latest/

码字很辛苦,转载请注明来自ChenJiehua《Sentry日志管理》

评论