From c95ae7e12a24bd816133b0fb2792ae0eed6b1f44 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Sun, 6 May 2018 00:11:01 +0200 Subject: [PATCH] [TASK] add procstat --- data/statistics.go | 25 +++++++++++++++++++++++-- database/influxdb/node.go | 13 +++++++++++++ database/influxdb/node_test.go | 6 ++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/data/statistics.go b/data/statistics.go index 19212d8..8479e83 100644 --- a/data/statistics.go +++ b/data/statistics.go @@ -30,8 +30,9 @@ type Statistics struct { MgmtTx *Traffic `json:"mgmt_tx"` MgmtRx *Traffic `json:"mgmt_rx"` } `json:"traffic,omitempty"` - Switch map[string]*SwitchPort `json:"switch,omitempty"` - Wireless WirelessStatistics `json:"wireless,omitempty"` + Switch map[string]*SwitchPort `json:"switch,omitempty"` + Wireless WirelessStatistics `json:"wireless,omitempty"` + ProcStats *ProcStats `json:"stat,omitempty"` } // MeshVPNPeerLink struct @@ -93,3 +94,23 @@ type Memory struct { type SwitchPort struct { 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"` +} diff --git a/database/influxdb/node.go b/database/influxdb/node.go index 56b7715..89c1d69 100644 --- a/database/influxdb/node.go +++ b/database/influxdb/node.go @@ -106,6 +106,19 @@ func (conn *Connection) InsertNode(node *runtime.Node) { // total is the sum of all protocols 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 { fields["traffic.rx.bytes"] = int64(t.Bytes) diff --git a/database/influxdb/node_test.go b/database/influxdb/node_test.go index 58ba694..ea5716e 100644 --- a/database/influxdb/node_test.go +++ b/database/influxdb/node_test.go @@ -17,6 +17,12 @@ func TestToInflux(t *testing.T) { Statistics: &data.Statistics{ NodeID: "deadbeef", LoadAverage: 0.5, + ProcStats: &data.ProcStats{ + CPU: data.ProcStatsCPU{ + User: 1, + }, + ContextSwitches: 3, + }, Wireless: data.WirelessStatistics{ &data.WirelessAirtime{Frequency: 5500}, },