mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-06 09:42:19 +00:00
eb70fc73cd
Former-commit-id: 25dc367490dd16ef4fa1d462118aa438df1b319a [formerly 6fab78aeb8b9f54fddbad1406f97392b753a830a] Former-commit-id: 0de0bb3ef9af1735ac8ecd1aefe2d57c0f76c62d
32 lines
749 B
Go
32 lines
749 B
Go
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) {
|
|
return json.Marshal(r.GetAll())
|
|
}
|
|
|
|
// 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) {
|
|
return json.Marshal(p.GetAll())
|
|
}
|