Refactor monitor.

Move function body to *.cc file
Modify GetTopicCount