需要构建一个 Python/Django “仪表板”替换管理员的系统电子邮件
对于我的 python/django 站点,我需要构建一个“仪表板”,它将更新我正在发生的数十个错误/心跳/意外事件的状态。
我目前正在通过 Django 站点向管理员帐户发送电子邮件来跟踪几种类型的“事件”:
1)正常情况下应该发生的事情出了问题。我们每隔几个小时将文件同步到不同的服务和其他机器,当出现问题时我会发送错误电子邮件。
2)当应该发生的事情确实发生时。有时,第 1 项中的事件会失败得如此严重,以至于它们甚至不发送电子邮件(尝试:例外:事件周围应该始终有效,但某些内容可能会从 crontab 中删除,系统配置可能会在某些情况下无法正常运行)运行等,我什至不会收到错误电子邮件,并且缺少成功/心跳电子邮件会让我知道应该发生的事情没有发生。)
3)当任何意外发生时。我们对后端操作将如何运行做出了很多假设,如果违反任何这些假设(例如,我们发现两个具有相同电子邮件地址的用户),我们想了解这一点。这些事件不一定是错误,更像是需要调查的警告。
因此,我想构建一个仪表板,我可以轻松地从 python/django 更新它,以鸟瞰所有这些类型的活动,这样我就可以停止每周发送数百封电子邮件(这已经难以管理)。
For my python/django site I need to build a "dashboard" that will update me on the status of dozens of error/heartbeat/unexpected events going on.
There are a few types of "events" that I'm currently tracking by having the Django site send emails to the admin accounts:
1) Something that normally should happen goes wrong. We synch files to different services and other machines every few hours and I send error emails when this goes wrong.
2) When something that should happen actually happens. Sometimes events in item #1 fail so horribly that they don't even send emails (try: except: around an event should always work, but things can get deleted from the crontab, the system configuration can get knocked askew where things won't run, etc. where I won't even get an error email and the lack of a success/heartbeat email will let me know something that should have happened didn't happen.)
3) When anything unexpected happens. We've made a lot of assumptions on how backend operations will run and if any of these assumptions are violated (e.g. we find two users who have the same email address) we want to know about it. These events aren't necessarily errors, more like warnings to investigate.
So I want to build a dashboard that I can easily update from python/django to give me a bird's eye view of all of these types of activity so I can stop sending hundreds of emails out per week (which is already unmanageble.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您想创建一个输出到网页的基本日志系统。
因此,您可以编写一个名为
systemevents
的简单应用程序,每当网站上发生某些事情时,它都会创建一个Event
记录。您可以添加一个信号挂钩,以便在站点的其余部分中的任何位置都可以编写类似以下内容的代码:然后您可以非常轻松地创建一个列出这些事件的视图。
然而,请记住,这会增加一层复杂性,从而带来很大的问题。如果错误出在您的数据库中怎么办?然后,每次您尝试记录错误事件时,都会发生另一个错误!
更好的方法是使用内置日志系统之类的东西来创建基于文本的日志文件,然后创建可以导入该文本文件并以更易读的方式布局的东西。
还有一点提示:为了改变 Django 处理异常的方式,你必须编写一个 500 个错误的自定义视图。如果使用
systemevents
,您将编写如下内容:请注意,此代码均未经过正确性测试。它只是作为指南。
Sounds like you want to create a basic logging system that outputs to a web page.
So you could write something simple app called, say,
systemevents
that creates anEvent
record each time something happens on the site. You'd add a signal hook so that anywhere in the rest of the site you could code something like:Then you can pretty easily create a view that lists these events.
However, keep in mind that this is adding a layer of complexity that is highly problematic. What if the error lies in your database? Then each time you try to record an error event, another error occurs!
Far better to use something like a built-in logging system to create a text-based log file, then whip up something that can import that text file and lay it out in a somewhat more readable fashion.
One more tip: in order to change how Django handles exceptions, you have to write a custom view for 500 errors. If using
systemevents
, you'd write something like:Note that none of this code has been tested for correctness. It's just meant as a guide.
您尝试过查看 django-sentry 吗?
http://dcramer.github.com/django-sentry/
Have you tried looking at django-sentry?
http://dcramer.github.com/django-sentry/