Commit 79dea08a authored by Your Name's avatar Your Name

monitor.dcgm:v.0.0.5

parent bef83893
......@@ -52,7 +52,7 @@ func (c *ProApi) Cpus() (Cpu, error) {
// inCpus := make(map[string]Cpu)
modelname, core, thread, err := c.CpuItems()
modelname, packageNum, core, thread, err := c.CpuItems()
if err != nil {
return Cpu{}, err
}
......@@ -78,13 +78,14 @@ func (c *ProApi) Cpus() (Cpu, error) {
Threads: int64(thread) + 1,
Cores: int64(core),
Frequency: strings.TrimSpace(freq),
Number: int64(packageNum),
}
return result, nil
}
// node_cpu_seconds_total{mode="idle"}
func (c ProApi) CpuItems() (string, int, int, error) {
func (c ProApi) CpuItems() (string, int, int, int, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
......@@ -93,7 +94,7 @@ func (c ProApi) CpuItems() (string, int, int, error) {
result, warnings, err := c.API.Query(ctx, queryParam, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return "", 0, 0, err
return "", 0, 0, 0, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
......@@ -111,6 +112,8 @@ func (c ProApi) CpuItems() (string, int, int, error) {
countCore := make(map[string]bool)
packageNum := make(map[string]bool)
for k, elem := range vectorVal {
// int64(elem.Value), nil
......@@ -141,11 +144,18 @@ func (c ProApi) CpuItems() (string, int, int, error) {
continue
}
if packageNumAsStr, ok := elem.Metric["package"]; ok {
packageNum[string(packageNumAsStr)] = true
} else {
continue
}
if cpuStr, ok := elem.Metric["cpu"]; ok {
newCpu, err := strconv.Atoi(string(cpuStr))
if err != nil {
return "", 0, 0, err
return "", 0, 0, 0, err
}
if newCpu > thread {
......@@ -167,10 +177,10 @@ func (c ProApi) CpuItems() (string, int, int, error) {
// c = c + 1
// }
return model_name, len(countCore), thread, nil
return model_name, len(packageNum), len(countCore), thread, nil
}
return "", 0, 0, errors.Errorf("cpu can not find the query %s value", queryParam)
return "", 0, 0, 0, errors.Errorf("cpu can not find the query %s value", queryParam)
}
......
version: "3.9"
services:
monitor.multi:
image: docker.ai.17xuexi.com/monitorapi/monitor.dcgm:v.0.0.4
monitor.dcgm:
image: docker.ai.17xuexi.com/monitorapi/monitor.dcgm:v.0.0.5
ports:
- 9093:9090
- 4000:4000
......
No preview for this file type
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