Skip to content

Commit

Permalink
get cpu cores from proc fs to fix cpufreq issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cha87de committed May 29, 2019
1 parent 043c486 commit 9cd19ca
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions collectors/cpucollector/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
)

func cpuLookupHost(host *models.Host) {
cpuinfo := util.GetSysCPU()

// calculate average of current cpu frequency
// collect cpu freq
cpufreqinfo := util.GetSysCPU()
coreFreqMin := []float64{}
coreFreqMax := []float64{}
coreFreqCurrent := []float64{}
for _, c := range cpuinfo {
for _, c := range cpufreqinfo {
// convert kHz to MHz
coreFreqMin = append(coreFreqMin, float64(c.MinFreq/1000))
coreFreqMax = append(coreFreqMax, float64(c.MaxFreq/1000))
Expand All @@ -29,7 +29,8 @@ func cpuLookupHost(host *models.Host) {
coreFreqCurMean := stat.Mean(coreFreqCurrent, nil)
host.AddMetricMeasurement("cpu_curfreq", models.CreateMeasurement(coreFreqCurMean))

cores := len(coreFreqCurrent)
cpuinfos := util.GetProcCpuinfo()
cores := len(cpuinfos)
host.AddMetricMeasurement("cpu_cores", models.CreateMeasurement(uint64(cores)))
}

Expand Down

0 comments on commit 9cd19ca

Please sign in to comment.