I think this functionality needs to be moved out of /lib, refactored a bit and moved into the DBStats model. I feel like much of this is something that could be handled in something like DBStats#save and a lot of the helper methods here should be encapsulated as private methods there as well. 

The /lib folder has a tendency to become a dumpster style catch all for rails projects and it's generally only recommended that you use it when you need to extend functionality in a gem or Ruby's core library.

Here's a good read on the topic:
http://reefpoints.dockyard.com/ruby/2012/02/14/love-your-lib-directory.html