mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-04-08 22:45:55 +02:00
Simplified code
This commit is contained in:
parent
a7f7422ebe
commit
048b52736c
@ -15,8 +15,6 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
var warnLog *log.Logger = log.New(os.Stderr, "Warning: ", log.LstdFlags)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// readOneLine reads one line from a file.
|
// readOneLine reads one line from a file.
|
||||||
// It returns ok when file was successfully read.
|
// It returns ok when file was successfully read.
|
||||||
@ -44,7 +42,7 @@ type CPUFreqCollectorCPU struct {
|
|||||||
// CPUFreqCollector
|
// CPUFreqCollector
|
||||||
// a metric collector to measure the current frequency of the CPUs
|
// a metric collector to measure the current frequency of the CPUs
|
||||||
// as obtained from the hardware (in KHz)
|
// as obtained from the hardware (in KHz)
|
||||||
// Only measured on the first hyper thread
|
// Only measure on the first hyper thread
|
||||||
//
|
//
|
||||||
// See: https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html
|
// See: https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html
|
||||||
//
|
//
|
||||||
@ -142,7 +140,8 @@ func (m *CPUFreqCollector) Init(config json.RawMessage) error {
|
|||||||
m.cpus,
|
m.cpus,
|
||||||
CPUFreqCollectorCPU{
|
CPUFreqCollectorCPU{
|
||||||
tagSet: map[string]string{
|
tagSet: map[string]string{
|
||||||
"coreID": strings.TrimSpace(coreID),
|
"type": "cpu",
|
||||||
|
"type-id": strings.TrimSpace(coreID),
|
||||||
"packageID": strings.TrimSpace(packageID),
|
"packageID": strings.TrimSpace(packageID),
|
||||||
},
|
},
|
||||||
scalingCurFreqFile: scalingCurFreqFile,
|
scalingCurFreqFile: scalingCurFreqFile,
|
||||||
@ -154,8 +153,9 @@ func (m *CPUFreqCollector) Init(config json.RawMessage) error {
|
|||||||
numPackages := strconv.Itoa(maxPackageID + 1)
|
numPackages := strconv.Itoa(maxPackageID + 1)
|
||||||
numCores := strconv.Itoa(maxCoreID + 1)
|
numCores := strconv.Itoa(maxCoreID + 1)
|
||||||
for i := range m.cpus {
|
for i := range m.cpus {
|
||||||
m.cpus[i].tagSet["num_core"] = numCores
|
c := &m.cpus[i]
|
||||||
m.cpus[i].tagSet["num_package"] = numPackages
|
c.tagSet["num_core"] = numCores
|
||||||
|
c.tagSet["num_package"] = numPackages
|
||||||
}
|
}
|
||||||
|
|
||||||
m.init = true
|
m.init = true
|
||||||
@ -167,21 +167,23 @@ func (m *CPUFreqCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cpu := range m.cpus {
|
now := time.Now()
|
||||||
|
for i := range m.cpus {
|
||||||
|
cpu := &m.cpus[i]
|
||||||
|
|
||||||
// Read current frequency
|
// Read current frequency
|
||||||
line, ok := readOneLine(cpu.scalingCurFreqFile)
|
line, ok := readOneLine(cpu.scalingCurFreqFile)
|
||||||
if !ok {
|
if !ok {
|
||||||
warnLog.Printf("CPUFreqCollector.Read(): Failed to read one line from file '%s'", cpu.scalingCurFreqFile)
|
log.Printf("CPUFreqCollector.Read(): Failed to read one line from file '%s'", cpu.scalingCurFreqFile)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cpuFreq, err := strconv.Atoi(line)
|
cpuFreq, err := strconv.Atoi(line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
warnLog.Printf("CPUFreqCollector.Read(): Failed to convert CPU frequency '%s': %v", line, err)
|
log.Printf("CPUFreqCollector.Read(): Failed to convert CPU frequency '%s': %v", line, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
value := map[string]interface{}{"value": cpuFreq}
|
y, err := lp.New("cpufreq", cpu.tagSet, m.meta, map[string]interface{}{"value": cpuFreq}, now)
|
||||||
y, err := lp.New("cpufreq", cpu.tagSet, m.meta, value, time.Now())
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user