views:

60

answers:

3

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.

A: 

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.

Jed Schneider
acts_as_versioned: I'm worry about performance, I'll have to hack it to use a different database (I don't want to mix production and reporting), I don't need all the methods (object.version.before, Object.version.after, etc.). But yes, this is something interesting.
VinceMD
I found a more modern gem, and there is a screencast : http://railscasts.com/episodes/177-model-versioning. But again, this is not acheving the same goal. I don't want to be able to go back to version 'xxx'. And I guess it's stopping the normal process flow for writing in versioning tables, so it's taking time.
VinceMD
i didn't really think of this last night, but i guess you could potentially use google analytics, but the CSV file is a good idea too or you could just write something like json key/value pairs to file and then not worry so much about the structure of the model changing.on the audit note, i was more thinking that the versions would allow you to build information based on auditing the status and date columns. not exactly sure on your specific need but you are on the right track i think.
Jed Schneider
A: 

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 ?

VinceMD
A: 

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. :)

VinceMD