What you try to achieve sounds like a job for the StatisticsOp. Unfortunately, this is not well documented in the current release. But a colleague of mine wrote a post which explains the usage.
Feel free to ask further questions if something is not clear in this description.