Commit 41574d3a authored by Your Name's avatar Your Name

fix cpu cores

parent 525e27ce
......@@ -76,7 +76,7 @@ func (c *ProApi) Cpus() (Cpu, error) {
Usage: totalUtil,
Model: modelname,
Threads: int64(thread) + 1,
Cores: int64(core) + 1,
Cores: int64(core),
Frequency: strings.TrimSpace(freq),
}
......@@ -107,9 +107,10 @@ func (c ProApi) CpuItems() (string, int, int, error) {
//res := make([]Cpu, 0, len(vectorVal))
model_name := ""
core := 0
thread := 0
countCore := make(map[string]bool)
for k, elem := range vectorVal {
// int64(elem.Value), nil
......@@ -126,14 +127,16 @@ func (c ProApi) CpuItems() (string, int, int, error) {
if coreStr, ok := elem.Metric["core"]; ok {
newCore, err := strconv.Atoi(string(coreStr))
if err != nil {
return "", 0, 0, err
}
countCore[string(coreStr)] = true
// newCore, err := strconv.Atoi(string(coreStr))
// if err != nil {
// return "", 0, 0, err
// }
// if newCore > core {
// core = newCore
// }
if newCore > core {
core = newCore
}
} else {
continue
}
......@@ -157,7 +160,14 @@ func (c ProApi) CpuItems() (string, int, int, error) {
// Model: model_name,
// })
}
return model_name, core, thread, nil
// c := 0
// for k, _ := range countCore {
// fmt.Println(c, k)
// c = c + 1
// }
return model_name, len(countCore), thread, nil
}
return "", 0, 0, errors.Errorf("cpu can not find the query %s value", queryParam)
......
package main
import "testing"
import (
"encoding/json"
"testing"
)
func TestCpuUtil(t *testing.T) {
func TestCpu(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
// cli, err := NewProCli("http://192.168.1.21:9090")
cli, err := NewProCli("http://47.94.59.74:9000/")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.CpuUtil()
gpus, err := cli.Cpus()
if err != nil {
t.Fatal(err)
}
for k, v := range gpus {
gpusAsJson, err := json.Marshal(gpus)
t.Log("k", k, "v", v)
if err != nil {
t.Fatal(err)
}
t.Log(string(gpusAsJson))
// for k, v := range gpus {
// t.Log("k", k, "v", v)
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment