Use a time.Ticker instead of the time.Sleep

This also prevents writing the metrics immediately after calling `WriteJSON`, which would likely be an empty registry in the beginning.
It would be nice to re-use the same `json.Encoder` as well, though that would make testing harder.