Skip to content

Commit

Permalink
main: Add a simple visualizer for stats
Browse files Browse the repository at this point in the history
Signed-off-by: Simarpreet Singh <[email protected]>
  • Loading branch information
simar7 committed Nov 17, 2019
1 parent 3a6ccf9 commit 808c8f5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/simar7/ebpfwall
go 1.13

require (
github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37
github.com/dropbox/goebpf v0.0.0-20191101224440-b4a5d6260e8c
github.com/stretchr/testify v1.4.0
github.com/vishvananda/netlink v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37 h1:uxxtrnACqI9zK4ENDMf0WpXfUsHP5V8liuq5QdgDISU=
github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
33 changes: 33 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"fmt"
"log"
"net"
"os"
"os/signal"
"strings"
"time"

tm "github.com/buger/goterm"
"github.com/dropbox/goebpf"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -93,4 +97,33 @@ func main() {
}
defer w.xdp.Detach()

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)

ticker := time.NewTicker(time.Second * 1)

for {
select {
case <-ticker.C:
tm.Clear()
tm.MoveCursor(1, 1)
_, _ = tm.Println("Current Time:", time.Now().Format(time.RFC1123))
table := tm.NewTable(0, 10, 5, ' ', 0)
_, _ = fmt.Fprintf(table, "IP\tDROPs\n")

for i := 0; i < len(w.IPAddrs); i++ {
value, err := w.Matches.Lookup(i)
if err != nil {
continue
}
_, _ = fmt.Fprintf(table, "%s\t%d\n", w.IPAddrs[i], value)
}
_, _ = tm.Println(table)
tm.Flush()
case <-interrupt:
w.lg.Info("Detaching and exiting..")
return
}
}

}

0 comments on commit 808c8f5

Please sign in to comment.