Added an optional timeout to metrics collection.

Review: https://reviews.apache.org/r/21092