respondd statistics

This commit is contained in:
Martin/Geno 2019-04-10 20:09:55 +02:00 committed by genofire
parent bd4699f561
commit d49b1bbf99
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
3 changed files with 31 additions and 14 deletions

View File

@ -29,12 +29,12 @@ type Daemon struct {
} }
type AnswerConfig struct { type AnswerConfig struct {
NodeID string `toml:"node_id"` NodeID string `toml:"node_id"`
Hostname string `toml:"hostname"` Hostname string `toml:"hostname"`
SiteCode string `toml:"site_code"` SiteCode string `toml:"site_code"`
DomainCode string `toml:"domain_code"` DomainCode string `toml:"domain_code"`
Location *data.Location `json:"location,omitempty"` Location *data.Location `json:"location,omitempty"`
VPN bool `toml:"vpn"` VPN bool `toml:"vpn"`
} }
func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) { func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) {

View File

@ -2,9 +2,9 @@ package respondd
import ( import (
"fmt" "fmt"
"net"
"os" "os"
"runtime" "runtime"
"net"
"github.com/FreifunkBremen/yanic/data" "github.com/FreifunkBremen/yanic/data"
) )
@ -54,12 +54,12 @@ func getAddresses(iface string) (addrs []string) {
for _, a := range inAddrs { for _, a := range inAddrs {
var ip net.IP var ip net.IP
switch v := a.(type) { switch v := a.(type) {
case *net.IPNet: case *net.IPNet:
ip = v.IP ip = v.IP
case *net.IPAddr: case *net.IPAddr:
ip = v.IP ip = v.IP
default: default:
continue continue
} }
if ip4 := ip.To4(); ip4 == nil { if ip4 := ip.To4(); ip4 == nil {
addrs = append(addrs, ip.String()) addrs = append(addrs, ip.String())

View File

@ -1,7 +1,9 @@
package respondd package respondd
import ( import (
"github.com/shirou/gopsutil/load"
"github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
"github.com/FreifunkBremen/yanic/data" "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 { if uptime, err := host.Uptime(); err == nil {
data.Statistics.Uptime = float64(uptime) 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)
}
} }