diff --git a/README.md b/README.md index 4e5e423..8139039 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ these configuration options: * **Filter:** BPF filter for this socket. If this is set, testimony will guarantee that the socket passed to child processes has this filter locked in such a way that clients cannot remove it. +* **NumberOfClients:** Use this option to specify the expected number of + clients to connect to the socket. ### Wire Protocol ### diff --git a/go/testimonyd/internal/socket/daemon.go b/go/testimonyd/internal/socket/daemon.go index 01d2823..b016ae1 100644 --- a/go/testimonyd/internal/socket/daemon.go +++ b/go/testimonyd/internal/socket/daemon.go @@ -51,6 +51,7 @@ type SocketConfig struct { FanoutID int // fanout id to avoid conflicts User, Group string // user/group to provide the socket to (will chown it) Filter string // BPF filter to apply to this socket + NumberOfClients int // Number of clients testimony working with } func (s SocketConfig) uid() (int, error) { diff --git a/go/testimonyd/internal/socket/socket.go b/go/testimonyd/internal/socket/socket.go index bc8ab94..aaeac9a 100644 --- a/go/testimonyd/internal/socket/socket.go +++ b/go/testimonyd/internal/socket/socket.go @@ -116,7 +116,7 @@ func newSocket(sc SocketConfig, fanoutID int, num int) (*socket, error) { // String returns a unique string for this socket. func (s *socket) String() string { - return fmt.Sprintf("[S:%v:%v]", s.conf.SocketName, s.num) + return fmt.Sprintf("[S:%v; fid:%v]", s.conf.SocketName, s.num) } // getNewBlocks is a goroutine that watches for new available packet blocks, @@ -149,12 +149,22 @@ func (s *socket) reportStats() { if err != nil { log.Printf("error getting statistics: %v", err) } else { - totalPackets += uint64(stats.tp_packets) - totalDrops += uint64(stats.tp_drops) - vlog.V(1, "%v stats: %d packets (%.02fpps), %d drops (%.02fpps) (%.02f%% dropped) since last log, %d packets, %d drops total (%.02f%% dropped)", s, - stats.tp_packets, float64(stats.tp_packets)/seconds, stats.tp_drops, float64(stats.tp_drops)/seconds, float64(stats.tp_drops)/float64(stats.tp_drops+stats.tp_packets)*100, + client_status := "delivered to client" + if len(s.currentConns) <= 0 { + client_status = "discarded by testimony" + } + if s.conf.NumberOfClients == 0 { + vlog.V(1, "%v stats: connected - %d clients", s, len(s.currentConns)) + } else { + vlog.V(1, "%v stats: connected - %d clients, still not connected - %d, therefore %v packets loosed for each unconnected client", s, len(s.currentConns), s.conf.NumberOfClients-len(s.currentConns), stats.tp_packets) + } + vlog.V(1, " %v stats: %d packets %v (%.02fpps), %d dropped in kernel (%.02fpps) (%.02f%% dropped) since last log, %d packets, %d drops total (%.02f%% dropped)", + s, stats.tp_packets, client_status, float64(stats.tp_packets)/seconds, + stats.tp_drops, float64(stats.tp_drops)/seconds, + float64(stats.tp_drops)/float64(stats.tp_drops+stats.tp_packets)*100, totalPackets, totalDrops, float64(totalDrops)/float64(totalPackets+totalDrops)*100) } + } }