Sentry

4 Notes
+ Sentry Supervisor Config File (Oct. 4, 2015, 10:15 a.m.)

[program:sentry-web] directory=/home/mohsen/virtualenvs/sentry environment=SENTRY_CONF="/home/mohsen/.sentry/sentry.conf.py" command=/home/mohsen/virtualenvs/sentry/bin/sentry --config=/home/mohsen/.sentry/sentry.conf.py start autostart=true autorestart=true redirect_stderr=true stdout_logfile=syslog stderr_logfile=syslog [program:sentry-worker] directory=/home/mohsen/virtualenvs/sentry environment=SENTRY_CONF="/home/mohsen/.sentry/sentry.conf.py" command=/home/mohsen/virtualenvs/sentry/bin/sentry celery worker -B user=sentry autostart=true autorestart=true redirect_stderr=true stdout_logfile=syslog stderr_logfile=syslog killasgroup=true

+ Sentry Nginx Config File (Oct. 3, 2015, 2:07 p.m.)

server { listen 80; server_name sentry.mohsenhassani.com; access_log /home/mohsen/logs/sentry_mohsenhassani.access.log; error_log /home/mohsen/logs/sentry_mohsenhassani.error.log; location / { proxy_pass http://localhost:9000; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }

+ Sentry Config File (Oct. 4, 2015, 10:15 a.m.)

# 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': { # You can swap out the engine for MySQL easily by changing this value # to ``django.db.backends.mysql`` or to PostgreSQL with # ``sentry.db.postgres`` # If you change this, you'll also need to install the appropriate python # package: psycopg2 (Postgres) or mysql-python 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'sentrydb', 'USER': 'sentry', 'PASSWORD': 'SentrY', 'HOST': '', '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 # ########### # The administrative email for this installation. # Note: This will be reported back to getsentry.com as the point of contact. See # the beacon documentation for more information. This **must** be a string. # SENTRY_ADMIN_EMAIL = 'your.name@example.com' SENTRY_ADMIN_EMAIL = 'mohsen@mohsenhassani.com' # 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 # ######### # 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'], # } # } # # SENTRY_CACHE = 'sentry.cache.django.DjangoCache' 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' ################ # 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 # ############## # You MUST configure the absolute URI root for Sentry: SENTRY_URL_PREFIX = 'http://sentry.mohsenhasani.com' # No trailing slash! # If you're using a reverse 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 SENTRY_WEB_HOST = '0.0.0.0' 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.3/topics/email/?from=olddocs#e-mail-backends EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'mail.mohsenhassani.com' EMAIL_HOST_PASSWORD = '4301Mohsen4301' EMAIL_HOST_USER = 'mohsen' EMAIL_PORT = 25 EMAIL_USE_TLS = False # The email address to send on behalf of SERVER_EMAIL = 'root@localhost' # 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 = ''

+ Installation and Configuration (Oct. 3, 2015, 3:41 p.m.)

For running sentry on my VPS, follow the following steps: 1-Create a virtualenv for 'sentry' and activate it (Do not use python3): virtualenv -p /usr/bin/python2.7 ~/virtualenvs/sentry source ~/virtualenvs/sentry/bin/activate 2-Before installing sentry, there are some packages you need to install: apt-get install python-setuptools python-pip python-dev libxslt1-dev libxml2-dev libz-dev libffi-dev libssl-dev libxslt1-dev 2-pip install sentry (There will be so many packages downloaded and installed. If any errors raised, check the error, you might need to install some more packages in spite of step 2 list.) 3- pip install sentry[postgres] 4- sentry init ~/.sentry/sentry.conf.py Using this command, a directory named `.sentry` and a python config file for your sentry will created at your home Open and manipulate the config file. Review it and change the default values based on your needs. (You can find the contents of my config file in this tutorial, by the title of 'Sentry Config File) 5-In the settings file, you set a URL name: sentry.mohsenhassani.com. Don't forget to create the sub domain using bind on you VPS. 6-Now you have to create the database: a) su (enter the password) b) su postgres c) createuser --pwprompt sentry d) createdb -O sentry sentrydb 7- You need to install `redis`: Redis is an open source in-memory data structure store, used as database, cache and message broker. It is a flexible, open-source, key value data store. apt-get install redis-server (it will run its server on localhost:6379 after installation automatically). 8-sentry --config=~/.sentry/sentry.conf.py upgrade It is used for migrations on the database and creating the initial schema. It will ask you to enter some information about the account and superuser information: Enter mohsen@mohsenhassani.com (for example for email) and a password. Choose (y) for using the same info as superuser. 9-To start the built-in webserver run: sentry --config=~/.sentry/sentry.conf.py start You should now be able to test the web service by visiting http://sentry.mohsenhassani.com:9000/. 10-For deploying Sentry with Nginx, create an Nginx config file in '~/configs/sentry'. (I have the contents of the file in my notes, in 'Sentry Nginx Config File'.) After restarting nginx (/etc/init.d/nginx restart) you'll be able to open sentry using: http://sentry.mohsenhassani.com 11-Sentry comes with a built-in queue to process tasks in a more asynchronous fashion. For example, with workers enabled, when an event comes in instead of writing it to the database immediately, it sends a job to the queue so that the request can be returned right away, and the background workers handle actually saving that data. When I ran the program I intended to log the errors, I would get the error in the sentry web after about 5 minutes. But using this following command I was able to get it in less than 10 seconds. sentry celery worker -B (This command is for tutorial only. It will be used in supervisor config file.) If you're going to use `supervisor` along with Sentry, you'll need to create a user for sentry and add it to suoders: adduser sentry (It does not matter what password you're entering) adduser sentry sudo Keep in mind that, when adding the supervisor config file, to get the `sentry-worker` work, you need to stop and start `supervisorctl`: killall supervisorctl supervisorctl Debugging: If the website did not open, for debugging refer to this path: /var/log/supervisor/supervisord.log You should be able to access '/admin/'. Enter the username and password of superuser and create a project, team, and stuff you need.