A little while ago one of the guys on a project I work one was asking about how many people were using the projects public web service. My first thought was to go grepping through logs. After all, the requests are right there and pretty consumable with a bit of Unix command line magic. But after a little discussion it became clear that would get old after a while. What about a week from now? How about a month or year? Few people want to go run commands and then manually correlate them. This lead to us looking around for some common solutions. The most obvious one was Google Analytics. To be honest I don’t much care about those systems. While that one may not (or may be) intrusive on users I just don’t feel all that comfortable forcing people to be subjected to a third party of a third party unless there is no other good choice. Luckily, being that the metrics are service related, the javascript/cookie/pixel based transaction wouldn’t have worked very well anyway.
So it was off to look at what others have made with a heavy eye towards Flask based solutions so it matched the same framework we were already using. Flask-Analytics came up in a search. The simple design was something I liked but the extension was more so aimed at using cookies to track users through an application while we want to track overall usage. I figured it was time to roll something ourselves and provide it back out to the community if they could use it as well.
Here it is in all it’s simplistic glory: Flask-Track-Usage. It doesn’t use cookies nor javascript and can store the results into any system which you provide a callable or Storage object. There is also FreeGeoIP integration for those what want to track where users are coming from. The code comes with a MongoDB Storage object for those who want to store the content back into their MongoDB. Want to know a bit more of the technical details? Check out the README or the project page. Patches welcome!
Nice tool. All my Flask app already use MongoDB, so that works well. Any thoughts on how to then analyse the results of the stored data in the Collection? Perhaps a sample Flask web site in the repo that does some basic work? I’m happy to help out, but was wondering what your thoughts were.
Thanks John!
The readthedocs site does have example code showing how to use the library. In terms of how to show the results, it depends on the backend storage used. One backend is MongoDB but other storage backends are available. We so provide a ger_usage method as part of Storage instances as a way to do a basic usage query. If you have specific requests please feel free to open up issues against the GitHub repo and/or send patches. I always enjoy collaborating with new people :-).
HTH