Added a metrics API.

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