我正在使用django-sentry来跟踪网站中的错误。我的问题是数据库变得太大了。 'message'表和'groupsmessage'是相关的
有没有办法清除旧条目和特定邮件,或者将哨兵表添加到django的管理员?
答案 0 :(得分:47)
使用cleanup命令。有两个参数:
使用它(--config
现已删除):
# sentry --config=sentry.conf.py cleanup --days 360
sentry cleanup --days 360
带有可选项目参数的OR ,它必须是整数:
# sentry --config=sentry.conf.py cleanup --days 360 --project 1
sentry cleanup --days 360 --project 1
在发现清理命令之前,我还能够使用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()
查看哨兵模型以查询其他对象。从这里你可以在对象上使用django ORM命令,如.save(),. remove()等。查看可用的哨兵模型here。如果您需要粒度,即修改对象,这种方法会更灵活一些。清理命令缺少的一件事是告诉你删除了多少个对象,它将删除的对象转储到屏幕上。
我的清理脚本看起来像这样,我使用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
答案 1 :(得分:7)
有一个cleanup命令。不幸的是,它的行为似乎没有记录,但code comments非常有用。
答案 2 :(得分:2)
要继续使用radtek的有用答案,如果您只想删除特定错误,我找到的最简单方法是在Group
对象上调用delete:
from sentry.models import Group
Group.objects.filter(culprit__contains='[SEARCH TERM]').delete()
[SEARCH TERM]
是您要删除的错误消息中显示的某些文字。
答案 3 :(得分:2)
这是使用official guide中默认docker-compose.yml
的dockerized Sentry实例执行清理的方法:
$ # Go to a directory containing the docker-compose.yml:
$ cd sentry-config
$ docker-compose run --rm worker cleanup --days 90
考虑阅读帮助:
$ docker-compose run --rm worker help
$ docker-compose run --rm worker cleanup --help
使用cron定期执行清理。运行crontab -e
并在其中添加以下行:
0 3 * * * cd sentry-config && docker-compose run --rm worker cleanup --days 30
在Postgres容器中运行VACUUM FULL {{relation_name}};
,不要忘记回收磁盘空间:
$ 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;
您可以在不指定关系的情况下运行VACUUM FULL;
,但这将锁定整个数据库。所以我建议逐个清除关系。 This is how you can find the size of your biggest relations.