[TASK] add procstat

This commit is contained in:
Martin/Geno 2018-05-06 00:11:01 +02:00
parent a05943bf0d
commit c95ae7e12a
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
3 changed files with 42 additions and 2 deletions

View File

@ -32,6 +32,7 @@ type Statistics struct {
} `json:"traffic,omitempty"` } `json:"traffic,omitempty"`
Switch map[string]*SwitchPort `json:"switch,omitempty"` Switch map[string]*SwitchPort `json:"switch,omitempty"`
Wireless WirelessStatistics `json:"wireless,omitempty"` Wireless WirelessStatistics `json:"wireless,omitempty"`
ProcStats *ProcStats `json:"stat,omitempty"`
} }
// MeshVPNPeerLink struct // MeshVPNPeerLink struct
@ -93,3 +94,23 @@ type Memory struct {
type SwitchPort struct { type SwitchPort struct {
Speed uint32 `json:"speed"` Speed uint32 `json:"speed"`
} }
// ProcStats struct
type ProcStats struct {
CPU ProcStatsCPU `json:"cpu"`
Intr uint64 `json:"intr"`
ContextSwitches uint64 `json:"ctxt"`
SoftIRQ uint64 `json:"softirq"`
Processes uint64 `json:"processes"`
}
// ProcStatsCPU struct
type ProcStatsCPU struct {
User uint64 `json:"user"`
Nice uint64 `json:"nice"`
System uint64 `json:"system"`
Idle uint64 `json:"idle"`
IOWait uint64 `json:"iowait"`
IRQ uint64 `json:"irq"`
SoftIRQ uint64 `json:"softirq"`
}

View File

@ -106,6 +106,19 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
// total is the sum of all protocols // total is the sum of all protocols
fields["neighbours.total"] = batadv + lldp fields["neighbours.total"] = batadv + lldp
} }
if procstat := stats.ProcStats; procstat != nil {
fields["stat.cpu.user"] = procstat.CPU.User
fields["stat.cpu.nice"] = procstat.CPU.Nice
fields["stat.cpu.system"] = procstat.CPU.System
fields["stat.cpu.idle"] = procstat.CPU.Idle
fields["stat.cpu.iowait"] = procstat.CPU.IOWait
fields["stat.cpu.irq"] = procstat.CPU.IRQ
fields["stat.cpu.softirq"] = procstat.CPU.SoftIRQ
fields["stat.intr"] = procstat.Intr
fields["stat.ctxt"] = procstat.ContextSwitches
fields["stat.softirq"] = procstat.SoftIRQ
fields["stat.processes"] = procstat.Processes
}
if t := stats.Traffic.Rx; t != nil { if t := stats.Traffic.Rx; t != nil {
fields["traffic.rx.bytes"] = int64(t.Bytes) fields["traffic.rx.bytes"] = int64(t.Bytes)

View File

@ -17,6 +17,12 @@ func TestToInflux(t *testing.T) {
Statistics: &data.Statistics{ Statistics: &data.Statistics{
NodeID: "deadbeef", NodeID: "deadbeef",
LoadAverage: 0.5, LoadAverage: 0.5,
ProcStats: &data.ProcStats{
CPU: data.ProcStatsCPU{
User: 1,
},
ContextSwitches: 3,
},
Wireless: data.WirelessStatistics{ Wireless: data.WirelessStatistics{
&data.WirelessAirtime{Frequency: 5500}, &data.WirelessAirtime{Frequency: 5500},
}, },