blob: 174b9477e92d69e80873f315b3cb0e7f425d91eb [file] [log] [blame]
khenaidooac637102019-01-14 15:44:34 -05001package metrics
2
3import (
4 "encoding/json"
5 "io"
6 "time"
7)
8
9// MarshalJSON returns a byte slice containing a JSON representation of all
10// the metrics in the Registry.
11func (r *StandardRegistry) MarshalJSON() ([]byte, error) {
12 return json.Marshal(r.GetAll())
13}
14
15// WriteJSON writes metrics from the given registry periodically to the
16// specified io.Writer as JSON.
17func WriteJSON(r Registry, d time.Duration, w io.Writer) {
18 for _ = range time.Tick(d) {
19 WriteJSONOnce(r, w)
20 }
21}
22
23// WriteJSONOnce writes metrics from the given registry to the specified
24// io.Writer as JSON.
25func WriteJSONOnce(r Registry, w io.Writer) {
26 json.NewEncoder(w).Encode(r)
27}
28
29func (p *PrefixedRegistry) MarshalJSON() ([]byte, error) {
30 return json.Marshal(p.GetAll())
31}