mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
Fix format for cpustat collector
This commit is contained in:
parent
e35a9f6b86
commit
e8b2bbdae1
@ -19,27 +19,27 @@ func (m *CpustatCollector) Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParseStatLine(line string, out map[string]interface{}) {
|
func ParseStatLine(line string, out map[string]interface{}) {
|
||||||
ls := strings.Fields(line)
|
ls := strings.Fields(line)
|
||||||
user, _ := strconv.ParseInt(ls[1], 0, 64)
|
user, _ := strconv.ParseInt(ls[1], 0, 64)
|
||||||
out["cpu_user"] = float64(user)
|
out["cpu_user"] = float64(user)
|
||||||
nice, _ := strconv.ParseInt(ls[2], 0, 64)
|
nice, _ := strconv.ParseInt(ls[2], 0, 64)
|
||||||
out["cpu_nice"] = float64(nice)
|
out["cpu_nice"] = float64(nice)
|
||||||
system, _ := strconv.ParseInt(ls[3], 0, 64)
|
system, _ := strconv.ParseInt(ls[3], 0, 64)
|
||||||
out["cpu_system"] = float64(system)
|
out["cpu_system"] = float64(system)
|
||||||
idle, _ := strconv.ParseInt(ls[4], 0, 64)
|
idle, _ := strconv.ParseInt(ls[4], 0, 64)
|
||||||
out["cpu_idle"] = float64(idle)
|
out["cpu_idle"] = float64(idle)
|
||||||
iowait, _ := strconv.ParseInt(ls[5], 0, 64)
|
iowait, _ := strconv.ParseInt(ls[5], 0, 64)
|
||||||
out["cpu_iowait"] = float64(iowait)
|
out["cpu_iowait"] = float64(iowait)
|
||||||
irq, _ := strconv.ParseInt(ls[6], 0, 64)
|
irq, _ := strconv.ParseInt(ls[6], 0, 64)
|
||||||
out["cpu_irq"] = float64(irq)
|
out["cpu_irq"] = float64(irq)
|
||||||
softirq, _ := strconv.ParseInt(ls[7], 0, 64)
|
softirq, _ := strconv.ParseInt(ls[7], 0, 64)
|
||||||
out["cpu_softirq"] = float64(softirq)
|
out["cpu_softirq"] = float64(softirq)
|
||||||
steal, _ := strconv.ParseInt(ls[8], 0, 64)
|
steal, _ := strconv.ParseInt(ls[8], 0, 64)
|
||||||
out["cpu_steal"] = float64(steal)
|
out["cpu_steal"] = float64(steal)
|
||||||
guest, _ := strconv.ParseInt(ls[9], 0, 64)
|
guest, _ := strconv.ParseInt(ls[9], 0, 64)
|
||||||
out["cpu_guest"] = float64(guest)
|
out["cpu_guest"] = float64(guest)
|
||||||
guest_nice, _ := strconv.ParseInt(ls[10], 0, 64)
|
guest_nice, _ := strconv.ParseInt(ls[10], 0, 64)
|
||||||
out["cpu_guest_nice"] = float64(guest_nice)
|
out["cpu_guest_nice"] = float64(guest_nice)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CpustatCollector) Read(interval time.Duration) {
|
func (m *CpustatCollector) Read(interval time.Duration) {
|
||||||
@ -49,20 +49,20 @@ func (m *CpustatCollector) Read(interval time.Duration) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ll := strings.Split(string(buffer), "\n")
|
ll := strings.Split(string(buffer), "\n")
|
||||||
for _, line := range ll {
|
for _, line := range ll {
|
||||||
if (len(line) == 0) {
|
if len(line) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ls := strings.Fields(line)
|
ls := strings.Fields(line)
|
||||||
if (strings.Compare(ls[0], "cpu") == 0) {
|
if strings.Compare(ls[0], "cpu") == 0 {
|
||||||
ParseStatLine(line, m.node)
|
ParseStatLine(line, m.node)
|
||||||
} else if (strings.HasPrefix(ls[0], "cpu")) {
|
} else if strings.HasPrefix(ls[0], "cpu") {
|
||||||
cpustr := strings.TrimLeft(ls[0], "cpu")
|
cpustr := strings.TrimLeft(ls[0], "cpu")
|
||||||
cpu, _ := strconv.Atoi(cpustr)
|
cpu, _ := strconv.Atoi(cpustr)
|
||||||
ParseStatLine(line, m.cpus[cpu])
|
ParseStatLine(line, m.cpus[cpu])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CpustatCollector) Close() {
|
func (m *CpustatCollector) Close() {
|
||||||
|
Loading…
Reference in New Issue
Block a user