mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
time.Tick() creates a ticker whose underlying resources can never be released because there is no handle to call Stop(). This is flagged by go vet (SA1015). 6 files in metrics/ fixed: debug.go, json.go, log.go, opentsdb.go, syslog.go, writer.go. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
795 B
Go
33 lines
795 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) {
|
|
ticker := time.NewTicker(d)
|
|
defer ticker.Stop()
|
|
for range ticker.C {
|
|
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 (r *PrefixedRegistry) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(r.GetAll())
|
|
}
|