mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
749 B
32 lines
749 B
7 years ago
|
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())
|
||
|
}
|