diff --git a/config/test.json b/config/test.json index 20ca93c..2cd1e43 100644 --- a/config/test.json +++ b/config/test.json @@ -20,7 +20,10 @@ "container": "go_proxy" }, "items": [{ - "keys": [ + "keys": [{ + "metric": "cpu.usage.sum", + "key": "sum" + }, { "metric": "cpu.usage.user", "key": "user" diff --git a/stat/cpu.go b/stat/cpu.go index 2996fd4..897fc54 100644 --- a/stat/cpu.go +++ b/stat/cpu.go @@ -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 { - // guestNice = util.StringToInt64(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]