业务监控工具 Sentry 的搭建与使用

官方网址

Django Sentry 官网链接

Sentry 简介

Sentry 是一个开源的实时错误报告工具,支持 web 前后端、移动应用以及游戏,支持 Python、OC、Java、Go、Node、Django、RoR 等主流编程语言和框架 ,还提供了 GitHub、Slack、Trello 等常见开发工具的集成。

Sentry 服务支持多用户、多团队、多应用管理,每个应用都对应一个 PROJECT_ID,以及用于身份认证的 PUBLIC_KEY 和 SECRET_KEY。由此组成一个这样的 DSN:

{PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}/{PATH}{PROJECT_ID}

PROTOCOL 通常会是 http 或者 https,HOST 为 Sentry 服务的主机名和端口,PATH 通常为空。

环境依赖

  1. Redis 搭建 / RabbitMQ 的搭建
  2. MySQL / PostgreSQL
  3. Python 虚拟环境

安装教程

A. Python 库文件: python-setuptools, python-dev, build-essential, python-pip

B. 安装虚拟环境: pip install virtualenv
安装完成后,可以直接 virtualenv xxx 即可在当前目录下生成一个虚拟环境xxx目录,进入到目录中,source bin/activate 即可激活当前虚拟环境。 C. 选择安装 virtualenvwrapper: pip install virtualenvwrapper
安装完成后,建立个虚拟环境安装存储的目录,建议是 $HOME/.virtualenv 目录,配置下 .bashrc 文件,文件末尾添加:
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh source .bashrc后,运行 mkvirtualenv xxx 即可建立虚拟环境。退出运行 deactivate。这样,就不需要再进入到虚拟环境目录运行 source xxx/activate,直接在终端输入 workon xxx 即可。
  • Sentry

    在虚拟环境下,直接运行 pip install sentry 即可。

这样,安装基本上就结束了。接下来需要配置下 sentry。

配置 Sentry

运行 sentry init, 会在 $HOME 下生成 .sentry 目录。进入 .sentry 后,需要修改数据库配置(当然,你也可以不改,直接使用 PostgreSQL):

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 这里换成了 MySQL,默认是 pq
'NAME': 'xxx',
'USER': 'xxx',
'PASSWORD': 'xxx',
'HOST': 'xxx',
'PORT': 'xxx',
}
}

端口和队列等可以自行指定。这里,我指定的是15000。下面是一个配置参考:

# This file is just Python, with a touch of Django which means
# you can inherit and tweak settings to your hearts content.
from sentry.conf.server import * import os.path CONF_ROOT = os.path.dirname(__file__) DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_sentry',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
'AUTOCOMMIT': True,
'ATOMIC_REQUESTS': False,
}
} # You should not change this setting after your database has been created
# unless you have altered all schemas first
SENTRY_USE_BIG_INTS = True # If you're expecting any kind of real traffic on Sentry, we highly recommend
# configuring the CACHES and Redis settings ###########
# General #
########### # Instruct Sentry that this install intends to be run by a single organization
# and thus various UI optimizations should be enabled.
SENTRY_SINGLE_ORGANIZATION = True
DEBUG = False #########
# Cache #
######### # Sentry currently utilizes two separate mechanisms. While CACHES is not a
# requirement, it will optimize several high throughput patterns. # If you wish to use memcached, install the dependencies and adjust the config
# as shown:
#
# pip install python-memcached
#
# CACHES = {
# 'default': {
# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
# 'LOCATION': ['127.0.0.1:11211'],
# }
# } # A primary cache is required for things such as processing events
SENTRY_CACHE = 'sentry.cache.redis.RedisCache' #########
# Queue #
######### # See https://docs.sentry.io/on-premise/server/queue/ for more
# information on configuring your queue broker and workers. Sentry relies
# on a Python framework called Celery to manage queues.
CELERY_ALWAYS_EAGER = False
BROKER_URL = 'redis://127.0.0.1:6379' ###############
# Rate Limits #
############### # Rate limits apply to notification handlers and are enforced per-project
# automatically. SENTRY_RATELIMITER = 'sentry.ratelimits.redis.RedisRateLimiter' ##################
# Update Buffers #
################## # Buffers (combined with queueing) act as an intermediate layer between the
# database and the storage API. They will greatly improve efficiency on large
# numbers of the same events being sent to the API in a short amount of time.
# (read: if you send any kind of real data to Sentry, you should enable buffers) SENTRY_BUFFER = 'sentry.buffer.redis.RedisBuffer' ##########
# Quotas #
########## # Quotas allow you to rate limit individual projects or the Sentry install as
# a whole. SENTRY_QUOTAS = 'sentry.quotas.redis.RedisQuota' ########
# TSDB #
######## # The TSDB is used for building charts as well as making things like per-rate
# alerts possible. SENTRY_TSDB = 'sentry.tsdb.redis.RedisTSDB' ###########
# Digests #
########### # The digest backend powers notification summaries. SENTRY_DIGESTS = 'sentry.digests.backends.redis.RedisBackend' ################
# File storage #
################ # Any Django storage backend is compatible with Sentry. For more solutions see
# the django-storages package: https://django-storages.readthedocs.org/en/latest/ SENTRY_FILESTORE = 'django.core.files.storage.FileSystemStorage'
SENTRY_FILESTORE_OPTIONS = {
'location': '/tmp/sentry-files',
} ##############
# Web Server #
############## # If you're using a reverse SSL proxy, you should enable the X-Forwarded-Proto
# header and uncomment the following settings
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SESSION_COOKIE_SECURE = True
# CSRF_COOKIE_SECURE = True # If you're not hosting at the root of your web server,
# you need to uncomment and set it to the path where Sentry is hosted.
# FORCE_SCRIPT_NAME = '/sentry' SENTRY_WEB_HOST = '0.0.0.0'
SENTRY_WEB_PORT = 5000
SENTRY_WEB_OPTIONS = {
# 'workers': 3, # the number of web workers
# 'protocol': 'uwsgi', # Enable uwsgi protocol instead of http
} LANGUAGES = (
('en', gettext_noop('English')),
('zh-cn', gettext_noop('Simplified Chinese')),
# ('zh-cn', gettext_noop('Traditional Chinese')),
)

运行 Sentry

  1. 初始化:
sentry upgrade

注意,这里可能会出现错误,可以参考下面遇到的坑。初始化的时候,需要设置一个 superuser 角色,直接按提示操作即可。

  1. 启动 web 进程:
sentry run web
  1. 启动 worker 进程:
sentry run worker
  1. 这时候,通过 IP:PORT 的形式访问下,填写刚才填写的用户名和密码即可登录。登录后,我们创建一个 project。我这里设置的是 Odeon_Dev,接下来选择项目,我选择的是 Django。这个时候,会弹出一个在项目中配置的教程。我们按照提示操作即可。

测试环境的地址:

http://localhost:5000/sentry/odeon_dev/

项目中配置 Sentry

按照上面的操作,Sentry 服务就可以 run 起来了。接下来需要在 Odeon 的项目中配置下 Sentry 环境即可。这里,我们需要引入一个新包: raven。我安装的 是 raven 6.1.0

安装:
A. 可以直接下载 raven 包,将其导入到环境中;
B. 直接指令安装: build/env/bin/pip install raven==6.1.0 项目配置:
直接将 sentry 创建 project 时返回的信息放入 settings 文件中即可 import os
import raven RAVEN_CONFIG = {
'dsn': 'http://fxxx:xxx@localhost:xxx/2',
'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
}

至此,整个 Sentry 的搭建和项目中需要的配置就完全 OK 了。

当然,也可以更完善一下,比如:

  1. 利用 Nginx 反向代理使用域名访问服务;
  2. 利用 supervisor 来起 Sentry 服务等。

接下来,就是按需使用了。

遇到的坑

  1. sentry默认使用 PostgreSQL。我用的是 mysql。运行 sentry upgrade 的时候,发现运行到 db migration 的时候抛了异常,查阅发现是 db engine 使用的是MyISAM,不支持 transaction 导致的。这里需要注意下,我将 engine 指定为 InnoDB后,执行 migration 的时候错误消失。

  2. 页面打开后,提示 worker 没有正常运行。发现没有启动 worker。我们手动启动下 worker,启动时,需要在系统中将 C_FORCE_ROOT 设置为 true。详细点击: 参考链接

参考链接:

Sentry的安装搭建与使用的更多相关文章

  1. centos6.5下Zabbix系列之Zabbix安装搭建及汉化

    最近在研究zabbix,在整理完成之后就有了写一下总结博客的想法,在我研究zabbix的时候给我很大帮助的是it你好,博客地址http://itnihao.blog.51cto.com/他做的zabb ...

  2. win7下安装搭建PHP环境

    由于最近新找的工作要求php,所以在电脑上安装搭建了PHP环境.主要参考了这篇文章http://www.leapsoul.cn/?p=695(之前第一次搭建时由于版本问题没有弄好) 1.先装apach ...

  3. centos6.5下Zabbix系列之Zabbix安装搭建及汉化 (转)

    最近在研究zabbix,在整理完成之后就有了写一下总结博客的想法,在我研究zabbix的时候给我很大帮助的是it你好,博客地址 http://itnihao.blog.51cto.com/他做的zab ...

  4. 【阿里云】在 Windows Server 2016 下使用 FileZilla Server 安装搭建 FTP 服务

     Windows Server 2016 下使用 FileZilla Server 安装搭建 FTP 服务 一.安装 Filezilla Server 下载最新版本的 Filezilla Server ...

  5. 一脸懵逼学习KafKa集群的安装搭建--(一种高吞吐量的分布式发布订阅消息系统)

    kafka的前言知识: :Kafka是什么? 在流式计算中,Kafka一般用来缓存数据,Storm通过消费Kafka的数据进行计算.kafka是一个生产-消费模型. Producer:生产者,只负责数 ...

  6. vue安装搭建

    title: vue安装搭建 date: 2018-04-21 14:00:03 tags: [vue] --- 安装 首先安装nodejs 直接官网下载最新版本http://nodejs.cn/do ...

  7. RabbitMQ,Windows环境下安装搭建

    切入正题:RabbitMQ的Windows环境下安装搭建 一.首先安装otp_win64_20.1.exe,,, 二.然后安装,rabbitmq-server-3.6.12.exe, 安装完成后,在服 ...

  8. Ubuntu14.04下Ambari安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)

    不多说,直接上干货! 写在前面的话 (1) 最近一段时间,因担任我团队实验室的大数据环境集群真实物理机器工作,至此,本人秉持负责.认真和细心的态度,先分别在虚拟机上模拟搭建ambari(基于CentO ...

  9. Ubuntu14.04下Cloudera安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)(在线或离线)

    第一步: Cloudera Manager安装之Cloudera Manager安装前准备(Ubuntu14.04)(一) 第二步: Cloudera Manager安装之时间服务器和时间客户端(Ub ...

随机推荐

  1. ES6关于Unicode的相关扩展

    前面的话 字符串是编程中重要的数据类型,只有熟练掌握字符串操作才能更高效地开发程序.JS中的字符串String类型是由引号括起来的一组由16位Unicode字符组成的字符序列.在过去,16位足以包含任 ...

  2. vue2中component父子组件传递数据props的使用

    子组件使用父亲传过来的数据,我们需要通过子组件的 props 选项. 组件实例的作用域是孤立的,不能在子组件的模板内直接引用父组件的数据.修改父亲传过来的props数据的时候 父亲必须传递对象,否则不 ...

  3. (转)xml

    1  XML理论回顾 1.1 XML概述 1.XML是可扩展标记语言.是由W3C指定并维护的,目前最新的版本是1.0 2.XML作用: 2.1传输数据,它是一种通用的数据交换格式 2.2配置文件. 1 ...

  4. Verilog HDL程序设计——基本要素

    Verilog基本上熟悉了,继续整理一下Verilog的学习笔记吧.前面记载了Verilog的结构,写Verilog的结构有了,但是该怎么写呢?在写之前就得了解一下Verilog的一些基本要素了,也就 ...

  5. myeclipse项目部署到idea常见问题

    由于myeclipse是付费产品,经过几次破解不成功后,遂弃之,转投IntelliJ IDEA门下.但这就出现一个问题了,以前用的eclipse.myeclipse以及spring tools sui ...

  6. CentOS6.3 下安装codeblocks

    本人用的系统是centos6.3(虚拟机) 需要预先安装gcc编译器(参考:http://www.cnblogs.com/magialmoon/archive/2013/05/05/3061108.h ...

  7. DynamicJSONserializer

    https://github.com/ststeiger/DynamicJSONserializer/blob/master/DynamicJSONserializer/Program.cs name ...

  8. .NET并行处理和并发1-Threads and Theading

    线程是操作系统分配处理器时间的基本单元,并且进程中可以有多个线程同时执行代码. 每个线程都维护异常处理程序.调度优先级和一组系统用于在调度该线程前保存线程上下文的结构. 线程上下文包括为使线程在线程的 ...

  9. linux几个重要的按键

    我们在用Windows系统时,有没有感觉快键键让我们工作更有效率,在Linux系统中仍有很好用的快捷键,这些快捷键可以辅助我们进行指令的编写与程序的中断呢,下面介绍几个经常用到的快捷键. 一.Tab- ...

  10. JavaScript入门之数组:Array类型详解

    数组应该是每个语言中都用得极度频繁的数据类型,JavaScript也不例外. 个人认为,Js中的Array类型非常强大. 首先没有C/C++等语言需要在数组初始化时指定数组长度(并不可变)的要求. 也 ...