如何清除/维护django-sentry数据库?

equ*_*ium 29 django sentry data-cleaning

我正在使用django-sentry来跟踪网站中的错误.我的问题是数据库变得太大了.'message'表和'groupsmessage'是相关的

有没有办法清除旧条目和特定消息或将哨兵表添加到django的管理员?

rad*_*tek 47

使用cleanup命令.有两个参数:

  • days(默认值:30) - 表示对象必须有多长时间才能清理它
  • project - 指示要删除的项目,因为您可以在单个sentry服务器中配置许多项目(默认值:all)

使用它(--config现在已删除):

# sentry --config=sentry.conf.py cleanup --days 360
sentry cleanup --days 360
Run Code Online (Sandbox Code Playgroud)

或者使用可选的项目参数,它必须是整数:

# sentry --config=sentry.conf.py cleanup --days 360 --project 1
sentry cleanup --days 360 --project 1
Run Code Online (Sandbox Code Playgroud)

在发现清理命令之前,我还能够使用django ORM手动执行此操作:

#$source bin/activate
#$sentry --config=sentry.conf.py shell
from sentry.models import Event, Alert
Event.objects.all().count()
Alert.objects.all().count()
Run Code Online (Sandbox Code Playgroud)

查看哨兵模型以查询其他对象.从这里你可以在对象上使用django ORM命令,如.save(),. remove()等.在这里查看可用的哨兵模型.如果您需要粒度(即修改对象),这种方法会更灵活一些.清理命令缺少的一件事是告诉你删除了多少个对象,它将删除的对象转储到屏幕上.

我的清理脚本看起来像这样,我使用cron运行@monthly:

#!/bin/bash
date
cd /var/web/sentry
source bin/activate
# exec sentry --config=sentry.conf.py cleanup --days 360 #--project 1
# UPDATE: You can now drop the --config param
exec sentry cleanup --days 360
Run Code Online (Sandbox Code Playgroud)

  • 另外,请记住经常运行该命令.因为它广泛使用Django ORM,如果数据库很大,它可能会在第一次运行****. (3认同)

Max*_*ysh 13

这是您使用dockerized哨兵实例与默认如何进行清理docker-compose.yml官方指导价

$ # Go to a directory containing the docker-compose.yml:
$ cd sentry-config  
$ docker-compose run --rm worker cleanup --days 90
Run Code Online (Sandbox Code Playgroud)

考虑阅读帮助:

$ docker-compose run --rm worker help
$ docker-compose run --rm worker cleanup --help
Run Code Online (Sandbox Code Playgroud)

使用 cron 定期执行清理。运行crontab -e并添加以下行:

0 3 * * *  cd sentry-config && docker-compose run --rm worker cleanup --days 30
Run Code Online (Sandbox Code Playgroud)

不要忘记通过VACUUM FULL {{relation_name}};在 Postgres 容器内运行来回收磁盘空间

$ docker exec -it {{postgres_container_id} /bin/bash
$ psql -U postgres
postgres=# VACUUM FULL public.nodestore_node;    
postgres=# VACUUM FULL {{ any large relation }};
postgres=# VACUUM FULL public.sentry_eventtag;
Run Code Online (Sandbox Code Playgroud)

您可以在VACUUM FULL;不指定关系的情况下运行,但这会锁定整个数据库。所以我建议一个一个地清理关系。这就是您可以找到最大关系规模的方法。


Dmi*_*nko 7

有一个清理命令.不幸的是,它的行为似乎没有记录,但代码注释非常有用.