Skip to content

Commit

Permalink
add test + change ctx switch attribute name
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed May 16, 2018
1 parent 7b41cac commit b9d0c40
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
36 changes: 21 additions & 15 deletions data/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,7 @@ type Statistics struct {
} `json:"traffic,omitempty"`
Switch map[string]*SwitchPort `json:"switch,omitempty"`
Wireless WirelessStatistics `json:"wireless,omitempty"`
ProcStats *struct {
CPU 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"`
} `json:"cpu"`
Intr uint64 `json:"intr"`
CTXT uint64 `json:"ctxt"`
SoftIRQ uint64 `json:"softirq"`
Processes uint64 `json:"processes"`
} `json:"stat,omitempty"`
ProcStats *ProcStats `json:"stat,omitempty"`
}

// MeshVPNPeerLink struct
Expand Down Expand Up @@ -108,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"`
}
2 changes: 1 addition & 1 deletion database/influxdb/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
fields["stat.cpu.irq"] = procstat.CPU.IRQ
fields["stat.cpu.softirq"] = procstat.CPU.SoftIRQ
fields["stat.intr"] = procstat.Intr
fields["stat.ctxt"] = procstat.CTXT
fields["stat.ctxt"] = procstat.ContextSwitches
fields["stat.softirq"] = procstat.SoftIRQ
fields["stat.processes"] = procstat.Processes
}
Expand Down
6 changes: 6 additions & 0 deletions database/influxdb/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down

0 comments on commit b9d0c40

Please sign in to comment.