mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
45 lines
954 B
Go
45 lines
954 B
Go
package collectors
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const LOADAVGFILE = `/proc/loadavg`
|
|
|
|
type LoadavgCollector struct {
|
|
MetricCollector
|
|
}
|
|
|
|
func (m *LoadavgCollector) Init() {
|
|
m.name = "LoadavgCollector"
|
|
m.setup()
|
|
}
|
|
|
|
func (m *LoadavgCollector) Read(interval time.Duration) {
|
|
buffer, err := ioutil.ReadFile(string(LOADAVGFILE))
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
ls := strings.Split(string(buffer), ` `)
|
|
loadOne, _ := strconv.ParseFloat(ls[0], 64)
|
|
m.node["load_one"] = float64(loadOne)
|
|
loadFive, _ := strconv.ParseFloat(ls[1], 64)
|
|
m.node["load_five"] = float64(loadFive)
|
|
loadFifteen, _ := strconv.ParseFloat(ls[2], 64)
|
|
m.node["load_fifteen"] = float64(loadFifteen)
|
|
lv := strings.Split(ls[3], `/`)
|
|
proc_run, _ := strconv.ParseFloat(lv[0], 64)
|
|
proc_total, _ := strconv.ParseFloat(lv[1], 64)
|
|
m.node["proc_total"] = float64(proc_total)
|
|
m.node["proc_run"] = float64(proc_run)
|
|
}
|
|
|
|
func (m *LoadavgCollector) Close() {
|
|
return
|
|
}
|