提交 a7507627 编写于 作者: G gwind

Fix interpretation error about /proc/stat

上级 79f276e1
......@@ -150,10 +150,6 @@ func parseStatLine(line string) (*CPUTimesStat, error) {
if err != nil {
return nil, err
}
stolen, err := strconv.ParseFloat(fields[8], 64)
if err != nil {
return nil, err
}
cpu_tick := float64(100) // TODO: how to get _SC_CLK_TCK ?
ct := &CPUTimesStat{
......@@ -165,24 +161,23 @@ func parseStatLine(line string) (*CPUTimesStat, error) {
Iowait: float64(iowait) / cpu_tick,
Irq: float64(irq) / cpu_tick,
Softirq: float64(softirq) / cpu_tick,
Stolen: float64(stolen) / cpu_tick,
}
if len(fields) > 9 { // Linux >= 2.6.11
steal, err := strconv.ParseFloat(fields[9], 64)
if len(fields) > 8 { // Linux >= 2.6.11
steal, err := strconv.ParseFloat(fields[8], 64)
if err != nil {
return nil, err
}
ct.Steal = float64(steal)
}
if len(fields) > 10 { // Linux >= 2.6.24
guest, err := strconv.ParseFloat(fields[10], 64)
if len(fields) > 9 { // Linux >= 2.6.24
guest, err := strconv.ParseFloat(fields[9], 64)
if err != nil {
return nil, err
}
ct.Guest = float64(guest)
}
if len(fields) > 11 { // Linux >= 3.2.0
guestNice, err := strconv.ParseFloat(fields[11], 64)
if len(fields) > 10 { // Linux >= 3.2.0
guestNice, err := strconv.ParseFloat(fields[10], 64)
if err != nil {
return nil, err
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册