yanic/respond/daemon/statistics.go

33 lines
979 B
Go
Raw Normal View History

2019-04-10 13:18:05 +02:00
package respondd
import (
2019-04-10 20:09:55 +02:00
"github.com/shirou/gopsutil/load"
2019-04-10 13:18:05 +02:00
"github.com/shirou/gopsutil/host"
2019-04-10 20:09:55 +02:00
"github.com/shirou/gopsutil/mem"
2019-04-10 13:18:05 +02:00
"github.com/FreifunkBremen/yanic/data"
)
func (d *Daemon) updateStatistics(iface string, data *data.ResponseData) {
_, nodeID := d.getAnswer(iface)
data.Statistics.NodeID = nodeID
if uptime, err := host.Uptime(); err == nil {
data.Statistics.Uptime = float64(uptime)
}
2019-04-10 20:09:55 +02:00
if m, err := mem.VirtualMemory(); err == nil {
data.Statistics.Memory.Cached = int64(m.Cached)
data.Statistics.Memory.Total = int64(m.Total)
data.Statistics.Memory.Buffers = int64(m.Buffers)
data.Statistics.Memory.Free = int64(m.Free)
data.Statistics.Memory.Available = int64(m.Available)
}
if v, err := load.Avg(); err == nil {
data.Statistics.LoadAverage = v.Load1
}
if v, err := load.Misc(); err == nil {
data.Statistics.Processes.Running = uint32(v.ProcsRunning)
//TODO fix after upstream
data.Statistics.Processes.Total = uint32(v.Ctxt)
}
2019-04-10 13:18:05 +02:00
}