From 510b466601ffed0d4c358cc9c715f5cf15f22a91 Mon Sep 17 00:00:00 2001 From: Ivan Danyliuk Date: Wed, 10 Jan 2018 23:19:52 +0100 Subject: [PATCH] Add netstats to csv output --- csv.go | 4 ++-- main.go | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/csv.go b/csv.go index 5cabd11..3d99dce 100644 --- a/csv.go +++ b/csv.go @@ -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() } diff --git a/main.go b/main.go index d7631aa..4e5e565 100644 --- a/main.go +++ b/main.go @@ -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()