added sum

This commit is contained in:
snoop 2017-11-17 18:24:58 +09:00
parent acce66b50f
commit 660a31ca7c
2 changed files with 22 additions and 18 deletions

View File

@ -20,7 +20,10 @@
"container": "go_proxy"
},
"items": [{
"keys": [
"keys": [{
"metric": "cpu.usage.sum",
"key": "sum"
},
{
"metric": "cpu.usage.user",
"key": "user"

View File

@ -5,8 +5,8 @@ import (
"io"
"strings"
"strconv"
"git.loafle.net/overflow/ssh_crawler/util"
)
//
type CPUStat struct {
@ -49,27 +49,28 @@ func (cpu CPUStat) Read(r io.Reader) (map[string]string, error) {
//if len(parts) > 9 {
// guest = util.StringToInt64(parts[9])
//}
//if len(parts) > 10 {
if len(parts) <= 10 {
//guestNice = util.StringToInt64(parts[10])
//}
continue
}
//stats = append(stats, CPUStat{
//Device := util.StringToInt64(parts[0])
//User := util.StringToInt64(parts[1])
//Nice := util.StringToInt64(parts[2])
//System := util.StringToInt64(parts[3])
//Idle := util.StringToInt64(parts[4])
//Iowait := util.StringToInt64(parts[5])
//Irq := util.StringToInt64(parts[6])
//SoftIrq := util.StringToInt64(parts[7])
//Steal := steal
//Guest := guest
//GuestNice := guestNice
User := util.StringToInt64(parts[1])
Nice := util.StringToInt64(parts[2])
System := util.StringToInt64(parts[3])
Idle := util.StringToInt64(parts[4])
Iowait := util.StringToInt64(parts[5])
Irq := util.StringToInt64(parts[6])
SoftIrq := util.StringToInt64(parts[7])
Steal := util.StringToInt64(parts[8])
Guest := util.StringToInt64(parts[9])
GuestNice := util.StringToInt64(parts[10])
//})
//sum := User + Nice + System + Idle + Iowait + Irq + SoftIrq + Steal + Guest + GuestNice
//resMap["sum"] = strconv.FormatInt(sum, 10)
sum := User + Nice + System + Idle + Iowait + Irq + SoftIrq + Steal + Guest + GuestNice
resMap["sum"] = strconv.FormatInt(sum, 10)
resMap["user"] = parts[1]
resMap["nice"] = parts[2]
resMap["system"] = parts[3]