diff --git a/experimental/tracer/main/http.go b/experimental/tracer/main/http.go index 414de7d4c..bec8c23bb 100644 --- a/experimental/tracer/main/http.go +++ b/experimental/tracer/main/http.go @@ -61,7 +61,7 @@ func (t *tracer) http(port int) { w.WriteHeader(204) }) - router.Methods("GET").Path("/trace").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + router.Methods("GET").Path("/traces").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { respondWith(w, http.StatusOK, t.store.Traces()) }) diff --git a/experimental/tracer/main/store.go b/experimental/tracer/main/store.go index a021f362c..2fe0a6b93 100644 --- a/experimental/tracer/main/store.go +++ b/experimental/tracer/main/store.go @@ -20,9 +20,9 @@ type key struct { } type trace struct { - pid int - root *ptrace.Fd - children []*trace + PID int + Root *ptrace.Fd + Children []*trace } type store struct { @@ -63,7 +63,7 @@ func (s *store) RecordConnection(pid int, connection *ptrace.Fd) { s.Lock() defer s.Unlock() - newTrace := &trace{pid: pid, root: connection} + newTrace := &trace{PID: pid, Root: connection} newTraceKey := newKey(connection) log.Printf("Recording trace: %+v", newTrace) @@ -75,7 +75,7 @@ func (s *store) RecordConnection(pid int, connection *ptrace.Fd) { parentNode.Remove() parentTrace := parentNode.Value.(*trace) log.Printf(" Found parent trace: %+v", parentTrace) - parentTrace.children = append(parentTrace.children, newTrace) + parentTrace.Children = append(parentTrace.Children, newTrace) } else { s.traces.Insert(newTraceKey, newTrace) } @@ -89,7 +89,7 @@ func (s *store) RecordConnection(pid int, connection *ptrace.Fd) { childNode.Remove() childTrace := childNode.Value.(*trace) log.Printf(" Found child trace: %+v", childTrace) - newTrace.children = append(newTrace.children, childTrace) + newTrace.Children = append(newTrace.Children, childTrace) } else { s.traces.Insert(childTraceKey, newTrace) } @@ -102,12 +102,9 @@ func (s *store) Traces() []*trace { var traces []*trace var cur = s.traces.First() - for { + for cur != nil { traces = append(traces, cur.Value.(*trace)) cur = cur.Next() - if cur == nil { - break - } } return traces } diff --git a/experimental/tracer/ptrace/fd.go b/experimental/tracer/ptrace/fd.go index 05138f4d0..b5f842fa5 100644 --- a/experimental/tracer/ptrace/fd.go +++ b/experimental/tracer/ptrace/fd.go @@ -35,14 +35,14 @@ type Fd struct { fd int Start int64 - stop int64 + Stop int64 sent int64 received int64 FromAddr net.IP FromPort uint16 - toAddr net.IP - toPort uint16 + ToAddr net.IP + ToPort uint16 // Fds are connections, and can have a causal-link to other Fds Children []*Fd @@ -120,6 +120,11 @@ func getLocalAddr(pid, fd int) (addr net.IP, port uint16, err error) { return } +// in milliseconds +func now() int64 { + return time.Now().UnixNano() / 1000000 +} + // We want to get the listening address from /proc func newListeningFd(pid, fd int) (*Fd, error) { localAddr, localPort, err := getLocalAddr(pid, fd) @@ -128,8 +133,8 @@ func newListeningFd(pid, fd int) (*Fd, error) { } return &Fd{ - direction: listening, fd: fd, Start: time.Now().Unix(), - toAddr: localAddr, toPort: uint16(localPort), + direction: listening, fd: fd, Start: now(), + ToAddr: localAddr, ToPort: uint16(localPort), }, nil } @@ -141,9 +146,9 @@ func newConnectionFd(pid, fd int, remoteAddr net.IP, remotePort uint16) (*Fd, er } return &Fd{ - direction: outgoing, fd: fd, Start: time.Now().Unix(), + direction: outgoing, fd: fd, Start: now(), FromAddr: localAddr, FromPort: uint16(localPort), - toAddr: remoteAddr, toPort: remotePort, + ToAddr: remoteAddr, ToPort: remotePort, }, nil } @@ -154,12 +159,12 @@ func (fd *Fd) newConnection(addr net.IP, port uint16, newFd int) (*Fd, error) { } return &Fd{ - direction: incoming, fd: newFd, Start: time.Now().Unix(), - toAddr: fd.toAddr, toPort: fd.toPort, + direction: incoming, fd: newFd, Start: now(), + ToAddr: fd.ToAddr, ToPort: fd.ToPort, FromAddr: addr, FromPort: port, }, nil } func (fd *Fd) close() { - fd.stop = time.Now().Unix() + fd.Stop = now() } diff --git a/experimental/tracer/ptrace/thread.go b/experimental/tracer/ptrace/thread.go index 6e90d26a0..8670e207c 100644 --- a/experimental/tracer/ptrace/thread.go +++ b/experimental/tracer/ptrace/thread.go @@ -168,7 +168,7 @@ func (t *thread) handleAccept(call, result *syscall.PtraceRegs) { t.process.newFd(connection) t.logf("Accepted connection from %s:%d -> %s:%d on fd %d, new fd %d", - addr, port, connection.toAddr, connection.toPort, listeningFdNum, connectionFdNum) + addr, port, connection.ToAddr, connection.ToPort, listeningFdNum, connectionFdNum) } func (t *thread) handleConnect(call, result *syscall.PtraceRegs) { @@ -192,7 +192,7 @@ func (t *thread) handleConnect(call, result *syscall.PtraceRegs) { } t.logf("Made connection from %s:%d -> %s:%d on fd %d", - connection.toAddr, connection.toPort, connection.FromAddr, + connection.ToAddr, connection.ToPort, connection.FromAddr, connection.FromPort, fd) } diff --git a/experimental/tracer/ui/index.html b/experimental/tracer/ui/index.html index c8a95dfb1..c6e71b631 100644 --- a/experimental/tracer/ui/index.html +++ b/experimental/tracer/ui/index.html @@ -12,102 +12,141 @@ + - + - - -
-
-

Weave Tracer

- -
- -
- -
-