Refactor monitor.

Move function body to *.cc file
Change GetTopicCount's argument from reference to pointer