expvarmon/expvars.go

43 lines
771 B
Go
Raw Normal View History

2015-04-21 17:51:01 +08:00
package main
import (
"encoding/json"
"io"
"runtime"
)
const ExpvarsUrl = "/debug/vars"
2015-04-25 20:54:17 +08:00
// ExpvarsSource implements Source interface for retrieving Expvars.
2015-04-21 17:51:01 +08:00
type ExpvarsSource struct {
Ports []string
}
type Expvars map[string]Expvar
type Expvar struct {
2015-04-25 20:54:17 +08:00
MemStats *runtime.MemStats `json:"memstats"`
Cmdline []string `json:"cmdline"`
2015-04-21 17:51:01 +08:00
Err error `json:"-,omitempty"`
}
func NewExpvarsSource(ports []string) *ExpvarsSource {
return &ExpvarsSource{
Ports: ports,
}
}
// ParseExpvar unmarshals data to Expvar variable.
2015-05-01 04:54:54 +08:00
// TODO: implement Unmarshaller/Decode for Expvar
2015-04-21 17:51:01 +08:00
func ParseExpvar(r io.Reader) (*Expvar, error) {
var vars Expvar
dec := json.NewDecoder(r)
err := dec.Decode(&vars)
if err != nil {
return nil, err
}
return &vars, err
}