Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Commit 2814819

Browse files
committed
Added clients counting functionality
1 parent 781c61a commit 2814819

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ these configuration options:
6666
* **Filter:** BPF filter for this socket. If this is set, testimony will
6767
guarantee that the socket passed to child processes has this filter locked
6868
in such a way that clients cannot remove it.
69+
* **NumberOfClients:** Use this option to specify the expected number of
70+
clients to connect to the socket.
6971

7072
### Wire Protocol ###
7173

go/testimonyd/internal/socket/daemon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type SocketConfig struct {
5151
FanoutID int // fanout id to avoid conflicts
5252
User, Group string // user/group to provide the socket to (will chown it)
5353
Filter string // BPF filter to apply to this socket
54+
NumberOfClients int // Number of clients testimony working with
5455
}
5556

5657
func (s SocketConfig) uid() (int, error) {

go/testimonyd/internal/socket/socket.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func newSocket(sc SocketConfig, fanoutID int, num int) (*socket, error) {
116116

117117
// String returns a unique string for this socket.
118118
func (s *socket) String() string {
119-
return fmt.Sprintf("[S:%v:%v]", s.conf.SocketName, s.num)
119+
return fmt.Sprintf("[S:%v; fid:%v]", s.conf.SocketName, s.num)
120120
}
121121

122122
// getNewBlocks is a goroutine that watches for new available packet blocks,
@@ -139,6 +139,7 @@ func (s *socket) getNewBlocks() {
139139

140140
func (s *socket) reportStats() {
141141
var totalPackets, totalDrops uint64
142+
var totalNotSent float64
142143
// getting statistics returns the stats since the last invocation. We clear
143144
// counters by doing an initial read we ignore.
144145
s.stats()
@@ -149,10 +150,20 @@ func (s *socket) reportStats() {
149150
if err != nil {
150151
log.Printf("error getting statistics: %v", err)
151152
} else {
152-
totalPackets += uint64(stats.tp_packets)
153-
totalDrops += uint64(stats.tp_drops)
154-
vlog.V(1, "%v stats: %d packets (%.02fpps), %d drops (%.02fpps) (%.02f%% dropped) since last log, %d packets, %d drops total (%.02f%% dropped)", s,
155-
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,
153+
client_status := "delivered to client"
154+
totalNotSent = float64(stats.tp_packets) - (float64(stats.tp_packets) * (float64(len(s.currentConns)) / (float64(s.conf.NumberOfClients * s.conf.FanoutSize))))
155+
if len(s.currentConns) <= 0 {
156+
client_status = "discarded by testimony"
157+
}
158+
if s.conf.NumberOfClients == 0 {
159+
vlog.V(1, " Connected - %d clients", len(s.currentConns))
160+
} else {
161+
vlog.V(1, " Connected - %d clients, still not connected - %d, therefore %v packets loosed ", len(s.currentConns), (s.conf.NumberOfClients*s.conf.FanoutSize)-len(s.currentConns), totalNotSent)
162+
}
163+
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)",
164+
s, stats.tp_packets, client_status, float64(stats.tp_packets)/seconds,
165+
stats.tp_drops, float64(stats.tp_drops)/seconds,
166+
float64(stats.tp_drops)/float64(stats.tp_drops+stats.tp_packets)*100,
156167
totalPackets, totalDrops, float64(totalDrops)/float64(totalPackets+totalDrops)*100)
157168
}
158169
}

0 commit comments

Comments
 (0)