Add netstats to csv output

This commit is contained in:
Ivan Danyliuk 2018-01-10 23:19:52 +01:00
parent 539f8657cf
commit 510b466601
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
2 changed files with 7 additions and 5 deletions

4
csv.go
View File

@ -29,7 +29,7 @@ func NewCSVDump() (*CSVDump, error) {
}
// Adds adds new CPU value to the CSV dump.
func (c *CSVDump) Add(value float64) {
func (c *CSVDump) Add(cpu float64, rx, tx int64) {
fd, err := os.OpenFile(c.file, os.O_APPEND|os.O_WRONLY|os.O_SYNC, 0644)
if err != nil {
// we just created this file, it should not dissapear :D
@ -38,6 +38,6 @@ func (c *CSVDump) Add(value float64) {
now := time.Now()
fd.WriteString(fmt.Sprintf("%d,%f\n", now.Unix(), value))
fd.WriteString(fmt.Sprintf("%d,%f,%d,%d\n", now.Unix(), cpu, rx, tx))
fd.Close()
}

View File

@ -86,9 +86,6 @@ func main() {
// update data
data.AddCPUValue(cpu)
if *csvdump {
csv.Add(cpu)
}
// netstats
rx, tx, err := src.Netstats()
@ -101,6 +98,11 @@ func main() {
data.AddNetworkStats(rx, tx)
// csv
if *csvdump {
csv.Add(cpu, rx, tx)
}
ui.UpdateCPU(data.CPU())
ui.UpdateNetstats(data.NetworkStats())
ui.Render()