github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/utilities/metrics/json.go (about) 1 package metrics 2 3 import ( 4 "encoding/json" 5 "io" 6 "time" 7 ) 8 9 func (r *StandardRegistry) MarshalJSON() ([]byte, error) { 10 return json.Marshal(r.GetAll()) 11 } 12 13 func WriteJSON(r Registry, d time.Duration, w io.Writer) { 14 for range time.Tick(d) { 15 WriteJSONOnce(r, w) 16 } 17 } 18 19 func WriteJSONOnce(r Registry, w io.Writer) { 20 json.NewEncoder(w).Encode(r) 21 } 22 23 func (p *PrefixedRegistry) MarshalJSON() ([]byte, error) { 24 return json.Marshal(p.GetAll()) 25 }