mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 02:45:42 +03:00
Add cpu.frequency, cpu.totalcompute
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
@@ -28,21 +28,33 @@ func (f *CPUFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bo
|
||||
}
|
||||
|
||||
var numCores int32
|
||||
numCores = 0
|
||||
var mhz float64
|
||||
var modelName string
|
||||
|
||||
// Assume all CPUs found have same Model. Log if not.
|
||||
// If CPUInfo() returns nil above, this loop is still safe
|
||||
for i, c := range cpuInfo {
|
||||
f.logger.Printf("(%d) Vendor: %s", i, c.VendorID)
|
||||
for _, c := range cpuInfo {
|
||||
numCores += c.Cores
|
||||
mhz += c.Mhz
|
||||
|
||||
if modelName != "" && modelName != c.ModelName {
|
||||
f.logger.Println("[WARN] Found different model names in the same CPU information. Recording last found")
|
||||
}
|
||||
modelName = c.ModelName
|
||||
}
|
||||
if numCores > 0 {
|
||||
node.Attributes["cpu.numcores"] = strconv.FormatInt(int64(numCores), 10)
|
||||
|
||||
if mhz > 0 {
|
||||
node.Attributes["cpu.frequency"] = fmt.Sprintf("%.6f", mhz)
|
||||
}
|
||||
|
||||
if numCores > 0 {
|
||||
node.Attributes["cpu.numcores"] = fmt.Sprintf("%d", numCores)
|
||||
}
|
||||
|
||||
if mhz > 0 && numCores > 0 {
|
||||
node.Attributes["cpu.totalcompute"] = fmt.Sprintf("%.6f", float64(numCores)*mhz)
|
||||
}
|
||||
|
||||
if modelName != "" {
|
||||
node.Attributes["cpu.modelname"] = modelName
|
||||
}
|
||||
|
||||
@@ -28,4 +28,11 @@ func TestCPUFingerprint(t *testing.T) {
|
||||
t.Fatalf("Missing Model Name")
|
||||
}
|
||||
|
||||
if node.Attributes["cpu.frequency"] == "" {
|
||||
t.Fatalf("Missing CPU Frequency")
|
||||
}
|
||||
if node.Attributes["cpu.totalcompute"] == "" {
|
||||
t.Fatalf("Missing CPU Total Compute")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user