|
|
|
@ -3,6 +3,8 @@ package cpu
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -95,8 +97,22 @@ func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c CPUTimesStat) String() string {
|
|
|
|
|
s, _ := json.Marshal(c)
|
|
|
|
|
return string(s)
|
|
|
|
|
v := []string{
|
|
|
|
|
`"cpu":"` + c.CPU + `"`,
|
|
|
|
|
`"user":` + strconv.FormatFloat(c.User, 'f', 1, 64),
|
|
|
|
|
`"system":` + strconv.FormatFloat(c.System, 'f', 1, 64),
|
|
|
|
|
`"idle":` + strconv.FormatFloat(c.Idle, 'f', 1, 64),
|
|
|
|
|
`"nice":` + strconv.FormatFloat(c.Nice, 'f', 1, 64),
|
|
|
|
|
`"iowait":` + strconv.FormatFloat(c.Iowait, 'f', 1, 64),
|
|
|
|
|
`"irq":` + strconv.FormatFloat(c.Irq, 'f', 1, 64),
|
|
|
|
|
`"softirq":` + strconv.FormatFloat(c.Softirq, 'f', 1, 64),
|
|
|
|
|
`"steal":` + strconv.FormatFloat(c.Steal, 'f', 1, 64),
|
|
|
|
|
`"guest":` + strconv.FormatFloat(c.Guest, 'f', 1, 64),
|
|
|
|
|
`"guest_nice":` + strconv.FormatFloat(c.GuestNice, 'f', 1, 64),
|
|
|
|
|
`"stolen":` + strconv.FormatFloat(c.Stolen, 'f', 1, 64),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return `{` + strings.Join(v, ",") + `}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c CPUInfoStat) String() string {
|
|
|
|
|