cc-metric-collector/collectors/loadavgMetric.go

40 lines
743 B
Go
Raw Normal View History

package collectors
import (
"io/ioutil"
"strconv"
"strings"
2021-03-25 17:47:08 +01:00
"time"
)
const LOADAVGFILE = `/proc/loadavg`
type LoadavgCollector struct {
MetricCollector
}
func (m *LoadavgCollector) Init() {
2021-03-25 17:47:08 +01:00
m.name = "LoadavgCollector"
m.setup()
}
2021-03-25 17:47:08 +01:00
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)
}
func (m *LoadavgCollector) Close() {
2021-03-25 17:47:08 +01:00
return
}