Skip to content

Commit 808c8f5

Browse files
committed
main: Add a simple visualizer for stats
Signed-off-by: Simarpreet Singh <simar@linux.com>
1 parent 3a6ccf9 commit 808c8f5

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/simar7/ebpfwall
33
go 1.13
44

55
require (
6+
github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37
67
github.com/dropbox/goebpf v0.0.0-20191101224440-b4a5d6260e8c
78
github.com/stretchr/testify v1.4.0
89
github.com/vishvananda/netlink v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37 h1:uxxtrnACqI9zK4ENDMf0WpXfUsHP5V8liuq5QdgDISU=
4+
github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
35
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
46
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
57
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import (
55
"fmt"
66
"log"
77
"net"
8+
"os"
9+
"os/signal"
810
"strings"
11+
"time"
912

13+
tm "github.com/buger/goterm"
1014
"github.com/dropbox/goebpf"
1115
"go.uber.org/zap"
1216
)
@@ -93,4 +97,33 @@ func main() {
9397
}
9498
defer w.xdp.Detach()
9599

100+
interrupt := make(chan os.Signal, 1)
101+
signal.Notify(interrupt, os.Interrupt)
102+
103+
ticker := time.NewTicker(time.Second * 1)
104+
105+
for {
106+
select {
107+
case <-ticker.C:
108+
tm.Clear()
109+
tm.MoveCursor(1, 1)
110+
_, _ = tm.Println("Current Time:", time.Now().Format(time.RFC1123))
111+
table := tm.NewTable(0, 10, 5, ' ', 0)
112+
_, _ = fmt.Fprintf(table, "IP\tDROPs\n")
113+
114+
for i := 0; i < len(w.IPAddrs); i++ {
115+
value, err := w.Matches.Lookup(i)
116+
if err != nil {
117+
continue
118+
}
119+
_, _ = fmt.Fprintf(table, "%s\t%d\n", w.IPAddrs[i], value)
120+
}
121+
_, _ = tm.Println(table)
122+
tm.Flush()
123+
case <-interrupt:
124+
w.lg.Info("Detaching and exiting..")
125+
return
126+
}
127+
}
128+
96129
}

0 commit comments

Comments
 (0)