sentry

### 参考 ###
http://readthedocs.org/docs/sentry/en/latest/index.html
http://raven.readthedocs.org/en/latest/config/index.html?highlight=key
http://blog.shanbay.com/archives/998

### 服务端安装 ###
#1 Setting up an Environment
easy_install -U virtualenv
virtualenv /www/sentry/
source /www/sentry/bin/activate

#2 Install Sentry
pip install sentry #easy_install -U sentry

#3 Initializing the Configuration
sentry init /etc/sentry.conf.py
//Configure db
///or psql
'ENGINE': 'postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'sentry',                      # Or path to database file if using sqlite3.
'USER': 'postgres',                      # Not used with sqlite3.
'PASSWORD': '*',                  # Not used with sqlite3.
'HOST': '127.0.0.1',                      # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5190',                      # Set to empty string for default. Not used with sqlite3.
'OPTIONS': {'autocommit': True,},

///or msyql
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sentry',
'USER': 'root',
'PASSWORD': '*',
'HOST': 'localhost',
'PORT': '3306',

///or sqlite
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(CONF_ROOT, 'sentry.db'),
'USER': 'postgres',
'PASSWORD': '',
'HOST': '',
'PORT': '',

//Configure Outbound Mail
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = '*'
EMAIL_HOST_USER = '*'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

SENTRY_PUBLIC = True
SENTRY_ALLOW_PROJECT_CREATION = True

#4 Running Migrations
#pip install psycopg2
#pip install MySQL-python
sentry --config=/etc/sentry.conf.py upgrade
//no create user
//must no exception

#5 create a new user
sentry --config=/etc/sentry.conf.py createsuperuser

#6 Starting the Web Service
sentry --config=/etc/sentry.conf.py start
//or
mkdir -p /www/sentry/log
nohup sentry --config=/etc/sentry.conf.py start >/www/sentry/log/sentry.log&

//or
/ebs_data/opt/typhoonae/etc/supervisord.conf
[program:sentry-web]
directory=/www/sentry/
command=/www/sentry/bin/sentry --config=/etc/sentry.conf.py start http
autostart=true
autorestart=true
redirect_stderr=true

///Restart supervisor
/ebs_data/opt/typhoonae/bin/supervisorctl shutdown
/ebs_data/opt/typhoonae/bin/supervisord

#7 Login with super user
http://x.x.x.x:9000/

#10 在sentry上创建相应的Project,在配置页面获取dsn添加到一下配置文件
/ebs_data/opt/typhoonae/parts/appsengine/etc/sentry_config.py

### 客户端安装 ###
#1 pip install raven

#2 在django的settings.py文件里的INSTALL_APPS加上一行:

INSTALLED_APPS = [
...
'raven.contrib.django',
]

#3 test
http://192.168.10.147:8080/tests?name=apps.base.tests.sentry_test



### 给模块新追加异常Logger的逻辑 ###
# 1,

import logging, logging.config
from typhoonae import log4

logging.config.fileConfig( log4._LOG_CONF_FILE )
logger = logging.getLogger("file_sync")
logger.setLevel(logging.DEBUG)

exception_logger = logging.getLogger("file_sync_except")
exception_logger.setLevel(logging.ERROR)
from raven.handlers.logging import SentryHandler
handler = SentryHandler('http://11c37937cf1849ceb381b5e092d25c02:[email protected]:9000/6')
exception_logger.addHandler(handler)


# 2,
import unittest
from apps.file_sync.log4 import exception_logger


class SentryTest(unittest.TestCase):

def setUp(self):
     pass

def tearDown(self):
     pass

def test_log_error(self):
     exception_logger.info('--------- file_sync test info ------------')
     exception_logger.error('--------- file_sync test error ------------')

猜你喜欢

转载自lifei0327.iteye.com/blog/1540403