From 461e8fd6e8e07c34994644d06fb29f0af089823c Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Wed, 10 Apr 2019 20:09:55 +0200 Subject: [PATCH] respondd statistics --- respond/daemon/config.go | 12 ++++++------ respond/daemon/nodeinfo.go | 16 ++++++++-------- respond/daemon/statistics.go | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/respond/daemon/config.go b/respond/daemon/config.go index 227bfa2f..376a1d8a 100644 --- a/respond/daemon/config.go +++ b/respond/daemon/config.go @@ -29,12 +29,12 @@ type Daemon struct { } type AnswerConfig struct { - NodeID string `toml:"node_id"` - Hostname string `toml:"hostname"` - SiteCode string `toml:"site_code"` - DomainCode string `toml:"domain_code"` - Location *data.Location `json:"location,omitempty"` - VPN bool `toml:"vpn"` + NodeID string `toml:"node_id"` + Hostname string `toml:"hostname"` + SiteCode string `toml:"site_code"` + DomainCode string `toml:"domain_code"` + Location *data.Location `json:"location,omitempty"` + VPN bool `toml:"vpn"` } func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) { diff --git a/respond/daemon/nodeinfo.go b/respond/daemon/nodeinfo.go index b1546b61..b7bbb045 100644 --- a/respond/daemon/nodeinfo.go +++ b/respond/daemon/nodeinfo.go @@ -2,9 +2,9 @@ package respondd import ( "fmt" + "net" "os" "runtime" - "net" "github.com/FreifunkBremen/yanic/data" ) @@ -47,19 +47,19 @@ func getAddresses(iface string) (addrs []string) { if err != nil { return } - inAddrs, err := in.Addrs() + inAddrs, err := in.Addrs() if err != nil { return } for _, a := range inAddrs { var ip net.IP switch v := a.(type) { - case *net.IPNet: - ip = v.IP - case *net.IPAddr: - ip = v.IP - default: - continue + case *net.IPNet: + ip = v.IP + case *net.IPAddr: + ip = v.IP + default: + continue } if ip4 := ip.To4(); ip4 == nil { addrs = append(addrs, ip.String()) diff --git a/respond/daemon/statistics.go b/respond/daemon/statistics.go index 0796980d..d414f22f 100644 --- a/respond/daemon/statistics.go +++ b/respond/daemon/statistics.go @@ -1,7 +1,9 @@ package respondd import ( + "github.com/shirou/gopsutil/load" "github.com/shirou/gopsutil/host" + "github.com/shirou/gopsutil/mem" "github.com/FreifunkBremen/yanic/data" ) @@ -12,4 +14,19 @@ func (d *Daemon) updateStatistics(iface string, data *data.ResponseData) { if uptime, err := host.Uptime(); err == nil { data.Statistics.Uptime = float64(uptime) } + 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) + } }