2019-11-18 20:33:15 +03:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MarshalJSON returns a byte slice containing a JSON representation of all
|
|
|
|
// the metrics in the Registry.
|
|
|
|
func (r *StandardRegistry) MarshalJSON() ([]byte, error) {
|
2020-06-25 00:20:22 +03:00
|
|
|
return json.Marshal(r.GetAll())
|
2019-11-18 20:33:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// WriteJSON writes metrics from the given registry periodically to the
|
|
|
|
// specified io.Writer as JSON.
|
|
|
|
func WriteJSON(r Registry, d time.Duration, w io.Writer) {
|
|
|
|
for _ = range time.Tick(d) {
|
|
|
|
WriteJSONOnce(r, w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteJSONOnce writes metrics from the given registry to the specified
|
|
|
|
// io.Writer as JSON.
|
|
|
|
func WriteJSONOnce(r Registry, w io.Writer) {
|
|
|
|
json.NewEncoder(w).Encode(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrefixedRegistry) MarshalJSON() ([]byte, error) {
|
2020-06-25 00:20:22 +03:00
|
|
|
return json.Marshal(p.GetAll())
|
2019-11-18 20:33:15 +03:00
|
|
|
}
|