respondd statistics traffic
This commit is contained in:
parent
c104fd01a7
commit
7934682ffb
|
@ -14,12 +14,12 @@ hostname = ""
|
||||||
site_code = "ffhb"
|
site_code = "ffhb"
|
||||||
domain_code = ""
|
domain_code = ""
|
||||||
vpn = false
|
vpn = false
|
||||||
|
traffic_interfaces = [ "eth0" ]
|
||||||
|
|
||||||
[defaults.location]
|
[defaults.location]
|
||||||
latitude = 53.112446246
|
latitude = 53.112446246
|
||||||
longitude = 8.734087944
|
longitude = 8.734087944
|
||||||
|
|
||||||
|
|
||||||
# if divergent configuration of defaults are wanted by respond on interface/zones example with bat0
|
# if divergent configuration of defaults are wanted by respond on interface/zones example with bat0
|
||||||
[zones.bat0]
|
[zones.bat0]
|
||||||
node_id = ""
|
node_id = ""
|
||||||
|
|
|
@ -36,6 +36,7 @@ type AnswerConfig struct {
|
||||||
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"`
|
||||||
|
TrafficInterfaces []string `toml:"traffic_interfaces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) {
|
func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) {
|
||||||
|
|
|
@ -4,29 +4,55 @@ import (
|
||||||
"github.com/shirou/gopsutil/host"
|
"github.com/shirou/gopsutil/host"
|
||||||
"github.com/shirou/gopsutil/load"
|
"github.com/shirou/gopsutil/load"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
|
"github.com/shirou/gopsutil/net"
|
||||||
|
|
||||||
"github.com/FreifunkBremen/yanic/data"
|
"github.com/FreifunkBremen/yanic/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *Daemon) updateStatistics(iface string, data *data.ResponseData) {
|
func (d *Daemon) updateStatistics(iface string, resp *data.ResponseData) {
|
||||||
_, nodeID := d.getAnswer(iface)
|
config, nodeID := d.getAnswer(iface)
|
||||||
data.Statistics.NodeID = nodeID
|
|
||||||
|
resp.Statistics.NodeID = nodeID
|
||||||
|
|
||||||
if uptime, err := host.Uptime(); err == nil {
|
if uptime, err := host.Uptime(); err == nil {
|
||||||
data.Statistics.Uptime = float64(uptime)
|
resp.Statistics.Uptime = float64(uptime)
|
||||||
}
|
}
|
||||||
if m, err := mem.VirtualMemory(); err == nil {
|
if m, err := mem.VirtualMemory(); err == nil {
|
||||||
data.Statistics.Memory.Cached = int64(m.Cached)
|
resp.Statistics.Memory.Cached = int64(m.Cached)
|
||||||
data.Statistics.Memory.Total = int64(m.Total)
|
resp.Statistics.Memory.Total = int64(m.Total)
|
||||||
data.Statistics.Memory.Buffers = int64(m.Buffers)
|
resp.Statistics.Memory.Buffers = int64(m.Buffers)
|
||||||
data.Statistics.Memory.Free = int64(m.Free)
|
resp.Statistics.Memory.Free = int64(m.Free)
|
||||||
data.Statistics.Memory.Available = int64(m.Available)
|
resp.Statistics.Memory.Available = int64(m.Available)
|
||||||
}
|
}
|
||||||
if v, err := load.Avg(); err == nil {
|
if v, err := load.Avg(); err == nil {
|
||||||
data.Statistics.LoadAverage = v.Load1
|
resp.Statistics.LoadAverage = v.Load1
|
||||||
}
|
}
|
||||||
if v, err := load.Misc(); err == nil {
|
if v, err := load.Misc(); err == nil {
|
||||||
data.Statistics.Processes.Running = uint32(v.ProcsRunning)
|
resp.Statistics.Processes.Running = uint32(v.ProcsRunning)
|
||||||
//TODO fix after upstream
|
//TODO fix after upstream
|
||||||
data.Statistics.Processes.Total = uint32(v.Ctxt)
|
resp.Statistics.Processes.Total = uint32(v.Ctxt)
|
||||||
|
}
|
||||||
|
if ls, err := net.IOCounters(true); err == nil {
|
||||||
|
resp.Statistics.Traffic.Tx = &data.Traffic{}
|
||||||
|
resp.Statistics.Traffic.Rx = &data.Traffic{}
|
||||||
|
|
||||||
|
allowedInterfaces := make(map[string]bool)
|
||||||
|
|
||||||
|
for _, iface := range config.TrafficInterfaces {
|
||||||
|
allowedInterfaces[iface] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range ls {
|
||||||
|
if i, ok := allowedInterfaces[s.Name]; !ok || !i {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resp.Statistics.Traffic.Tx.Bytes = float64(s.BytesSent)
|
||||||
|
resp.Statistics.Traffic.Tx.Packets = float64(s.PacketsSent)
|
||||||
|
resp.Statistics.Traffic.Tx.Dropped = float64(s.Dropout)
|
||||||
|
|
||||||
|
resp.Statistics.Traffic.Rx.Bytes = float64(s.BytesRecv)
|
||||||
|
resp.Statistics.Traffic.Rx.Packets = float64(s.PacketsRecv)
|
||||||
|
resp.Statistics.Traffic.Rx.Dropped = float64(s.Dropin)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue