mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-21 06:20:31 +00:00
walk events instead of printing directly
This commit is contained in:
@@ -2,7 +2,6 @@ package endpoint
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -32,7 +31,8 @@ type ConnectionEvent struct {
|
||||
}
|
||||
|
||||
type EbpfTracker struct {
|
||||
Cmd *exec.Cmd
|
||||
Cmd *exec.Cmd
|
||||
Events []ConnectionEvent
|
||||
}
|
||||
|
||||
func NewEbpfTracker(bccProgramPath string) *EbpfTracker {
|
||||
@@ -135,6 +135,13 @@ func (t *EbpfTracker) run() {
|
||||
DestPort: dPort,
|
||||
}
|
||||
|
||||
fmt.Println(e)
|
||||
t.Events = append(t.Events, e)
|
||||
}
|
||||
}
|
||||
|
||||
// WalkEvents - walk through the connectionEvents
|
||||
func (t *EbpfTracker) WalkEvents(f func(ConnectionEvent)) {
|
||||
for _, event := range t.Events {
|
||||
f(event)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,12 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
time.Sleep(100 * time.Second)
|
||||
// create some http connection within these 10 seconds
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
tr.WalkEvents(func(e endpoint.ConnectionEvent) {
|
||||
fmt.Println(e)
|
||||
})
|
||||
|
||||
fmt.Println("done")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user