Sentry1 is a modern error logging and aggregation platform.
The Sentry package fundamentally is just a simple server and web UI. It will handle authenticating clients (such as Raven) and all of the logic behind storage and aggregation.Sentry2 is not limited to Python. The primary implementation is in Python, but it contains a full API for sending events from any language, in any application.
The Sentry Server is the core Python application that powers all of the Sentry installations.
This guide will step you through setting up a Python-based virtualenv, installing the required packages, and configuring the basic web service.3
Here I will give some more detailed steps.You can find more information from Sentry official website.
A UNIX-based operating system. We test on Ubuntu and this documentation assumes an ubuntu based system.
You could find the latest dependency from from here.
https://www.python.org/downloads/
Install redis
$ wget http://download.redis.io/releases/redis-3.0.6.tar.gz
$ tar xzf redis-3.0.6.tar.gz
$ cd redis-3.0.6
$ make
Run redis
$ src/redis-server
save problem: try sudo vim redis.conf
, and find “dir ./ “. The default value is: ./ and change it to “/root/path/to/dir/with/write/access/”
Note that you must specify a directory here, not a file name.
dir /root/path/to/dir/with/write/access/
Install postgresql
try this command:
apt-get install postgresql-9.4
if it does not work, try to use the PostgreSQL Apt Repository. and try the following method. You can get more detail from here and its wiki.
- (You may determine the codename of your distribution by running lsb_release -c). For a shorthand version of the above, presuming you are using a supported release:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- Import the repository key from https://www.postgresql.org/media/keys/ACCC4CF8.asc , update the package lists, and start installing packages:
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install postgresql-9.4 pgadmin3
install python-setuptools, python-pip, python-dev, libxslt1-dev, libxml2-dev, libz-dev, libffi-dev, libssl-dev, libssl-dev, libpq-dev, libyaml-dev.
sudo apt-get install python-setuptools python-pip python-dev libxslt1-dev libxml2-dev libz-dev libffi-dev libssl-dev libpq-dev libyaml-dev
sudo apt-get install nginx
pip install -U virtualenv
Once that is done, choose a location for the environment, and create it with the virtualenv command. For our guide, we’re going to choose /www/sentry/:
sudo mkdir -p /www/sentry/
virtualenv /www/sentry/
Finally, activate your virtualenv:
source /www/sentry/bin/activate
Once you’re got the environment setup, you can install Sentry and all its dependencies with the same command you used to grab virtualenv:
pip install -U sentry
Now you’l need to create the default configuration. To do this, you’l use the init command You can specify an alternative configuration path as the argument to init, otherwise it will use the default of ~/.sentry.
# the path is optional
sentry init /www/sentry/
Sentry provides an easy way to run migrations on the database on version upgrades. Before running it for the first time you’l need to make sure you’e created the database:
# If you're using Postgres, and kept the database ``NAME`` as ``sentrydb``
sudo -u postgres psql
create user "" with password '' ;
create database "sentrydb" with owner="" ;
\q
Once done, you can create the initial schema using the upgrade command:
$ SENTRY_CONF=/www/sentry/sentry.conf.py sentry upgrade
During the upgrade, You can create the first user.
If not,next up you’l need to create the first user, which will act as a superuser:
# create a new user
$ SENTRY_CONF=/www/sentry/sentry.conf.py sentry createuser
sudo vim /www/sentry/sentry.conf.py
Here is my configuration of sentry for test. You can find more support from Sentry Official website4.
Note line 12,13,14,15,155,156,158,171,172,173,174
# 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': 'sentry.db.postgres',
'NAME': 'sentrydb',
'USER': '' ,
'PASSWORD': '' ,
'HOST': '127.0.0.1',
'PORT': '',
}
}
# 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
#########
# Redis #
#########
# Generic Redis configuration used as defaults for various things including:
# Buffers, Quotas, TSDB
SENTRY_REDIS_OPTIONS = {
'hosts': {
0: {
'host': '127.0.0.1',
'port': 6379,
}
}
}
#########
# 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.getsentry.com/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://localhost: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
# If you're not hosting at the root of your web server, and not using uWSGI,
# you need to uncomment and set it to the path where Sentry is hosted.
# FORCE_SCRIPT_NAME = '/sentry'
SENTRY_WEB_HOST = '' #your machine ip
SENTRY_WEB_PORT = 9000
SENTRY_WEB_OPTIONS = {
'workers': 3, # the number of gunicorn workers
# 'secure_scheme_headers': {'X-FORWARDED-PROTO': 'https'},
}
###############
# Mail Server #
###############
# For more information check Django's documentation:
# https://docs.djangoproject.com/en/1.6/topics/email/
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = '[email protected]'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
# The email address to send on behalf of
SERVER_EMAIL = '[email protected]'
# If you're using mailgun for inbound mail, set your API key and configure a
# route to forward to /api/hooks/mailgun/inbound/
MAILGUN_API_KEY = ''
sudo sentry --config=/www/sentry/sentry.conf.py start
You should now be able to test the web service by visiting http://localhost:9000/
sudo pip install supervisor -U
sudo echo_supervisord_conf > /etc/supervisord.conf
or try this
#echo to some file and then copy to ...
echo_supervisord_conf > supervisord.conf
sudo vim supervisord.conf
add the following content:
[program:sentry-web]
directory=/www/sentry/
command=sentry start
autostart=true
autorestart=true
redirect_stderr=true
stopasgroup=true
killasgroup=true
environment=SENTRY_CONF="/www/sentry/sentry.conf.py"
[program:sentry-worker]
directory=/www/sentry/
command=sentry celery worker -B -l INFO
autostart=true
autorestart=true
redirect_stderr=true
stopasgroup=false
killasgroup=true
environment=SENTRY_CONF="/www/sentry/sentry.conf.py",C_FORCE_ROOT="true"
[program:sentry-cron]
directory=/www/sentry/
command=sentry celery beat
autostart=true
autorestart=true
redirect_stderr=true
killasgroup=true
environment=SENTRY_CONF="/www/sentry/sentry.conf.py"
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
username=user ; (default is no username (open server))
password=123 ; (default is no password (open server))
save /etc/supervisord.conf, and start superviord(see below). Now you can browse from http://127.0.0.1:9001
sudo supervisord -c /etc/supervisord.conf
sudo supervisorctl -c /etc/supervisord.conf stop all
sudo supervisorctl -c /etc/supervisord.conf shutdown