mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-27 07:39:05 +01:00
46 lines
972 B
Go
46 lines
972 B
Go
package collectors
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const LOADAVGFILE = `/proc/loadavg`
|
|
|
|
type LoadavgCollector struct {
|
|
MetricCollector
|
|
}
|
|
|
|
func (m *LoadavgCollector) Init() error {
|
|
m.name = "LoadavgCollector"
|
|
m.setup()
|
|
return nil
|
|
}
|
|
|
|
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
|
|
}
|