Hello Janine.
It's quite simple. What I did was to enable PGSQL to keep stats and then you can query some tables that contain all that information. You can see more in the postgresql docs.
Hope this helps,
/B