mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-07-31 08:56:06 +02:00
Add simpler collectors for load, mem_used and network
This commit is contained in:
36
collectors/loadavgMetric.go
Normal file
36
collectors/loadavgMetric.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package collectors
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (m *LoadavgCollector) Close() {
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user