如何将生产数据存储到 Rails 应用程序中的报告数据库?
我们想要跟踪 Rails 应用程序的生产数据,以便我们可以在几个月内对其进行分析。
更准确地说,我们有一些数据模型,其中的“状态”和日期列可能会经常更改。 这个想法是每次状态或任何其他属性发生变化时在数据库或日志文件中的某个位置写入新行。这些行包含该对象的所有属性的副本。
我看到了不同的解决方案:
- 将保存的数据复制到报告 Mysql 数据库
- 使用带有 after_save 的观察者,并使用记录器系统
- 。在数据库级别执行不同的级别,检测表中的更改并将受影响的行复制到报告数据库。
提取数据比将数据存储在数据库中更容易。日志文件速度更快,并且不会减慢进程太多。我不知道什么是最好的方法或者是否有任何其他解决方案/实现。
We want to keep track of production data of a Rails app, so that we can analyse them in a few months.
To be more precise, we have a few data Models with a "status" and dates column that can change frequently.
The idea is to write somewhere a new line in a DB or log file every time the status or any other attribute changes. These line consists in a copy of all the attributes for this object.
I see different solutions:
- using observer with after_save, and replicate the saved data to a reporting Mysql Db
- using a logger system.
- do it a different level, on the DB level, detecting changes in a table and copying the affected rows to the reporting DB.
It's easier to extract data then if they are stored in a DB. Log files are faster and don't slow down the process that much. I can't figure out what is the best way or if there is any other solution/implementation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你看过acts_as_versioned吗?我确信有一个为此目的而编写的更现代的库,但它可能会实现您所需要的:在更新时对数据进行版本控制,以便您以后可以跟踪它。不管怎样,它可能会给你一个可供参考的模板。
have you looked at acts_as_versioned? I'm sure there is a more modern library written for this purpose, but it might accomplish what you need: versioning the data on update so you can keep track of it later. It may give you a template to go by, anyway.
有一个选项作为 gem: http://github.com/andersondias/acts_as_auditable
现在我'我在保存在审核表中还是保存在 CVS 格式的文件之间犹豫不决。我的感觉是第二个选项更好,因为写入文件速度更快,而且我们不依赖于与数据库服务器的连接。
任何单个 BI 工具都可以使用 CVS 文件作为数据源。问题是每次更改表的结构时我都必须创建不同的文件。但这有问题吗?
There is an option as a gem: http://github.com/andersondias/acts_as_auditable
Now I'm hesitating between saving in a audit table or saving in file with CVS format. My feeling is that the second option is better, because writting in file is faster and we don't depend on a connexion to a database server.
Any single BI tool is able to use a CVS file as a data source. The problem is I have to create a different file each time I change the structure of my table. But is it a problem ?
我最终使用了观察者和具有 FasterCSV 的记录器来生成审核日志。
我无法正确复制/粘贴所有代码,因此对于感兴趣的人,这里有一个博客文章的链接:
记录 Rails 生产数据以执行一些审核 (bi)
这可以轻松适应任何 Rails 模型。 :)
I finally used an observer, and a Logger with FasterCSV to generate audit log.
I wasn't able to copy/paste all the code properly, so here is a link to a blog post, for those who are interested:
log rails production data to perform some audit (bi)
This can be easily adapted for any Rails Model. :)