mirror of
https://github.com/divan/expvarmon.git
synced 2025-04-27 13:48:55 +08:00
42 lines
721 B
Go
42 lines
721 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"runtime"
|
|
)
|
|
|
|
const ExpvarsUrl = "/debug/vars"
|
|
|
|
// ExpvarsSource implements Source interface for retrieving Expvars.
|
|
type ExpvarsSource struct {
|
|
Ports []string
|
|
}
|
|
|
|
type Expvars map[string]Expvar
|
|
|
|
type Expvar struct {
|
|
MemStats *runtime.MemStats `json:"memstats"`
|
|
Cmdline []string `json:"cmdline"`
|
|
|
|
Err error `json:"-,omitempty"`
|
|
}
|
|
|
|
func NewExpvarsSource(ports []string) *ExpvarsSource {
|
|
return &ExpvarsSource{
|
|
Ports: ports,
|
|
}
|
|
}
|
|
|
|
// ParseExpvar unmarshals data to Expvar variable.
|
|
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
|
|
}
|