mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-09 17:18:50 +00:00
serve: display number of connections.
This commit is contained in:
17
serve.go
17
serve.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
@@ -104,6 +105,15 @@ var serve = &cli.Command{
|
|||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
totalConnections := atomic.Int32{}
|
||||||
|
rl.OnConnect = func(ctx context.Context) {
|
||||||
|
totalConnections.Add(1)
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
totalConnections.Add(-1)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
d := debounce.New(time.Second * 2)
|
d := debounce.New(time.Second * 2)
|
||||||
printStatus = func() {
|
printStatus = func() {
|
||||||
d(func() {
|
d(func() {
|
||||||
@@ -113,7 +123,12 @@ var serve = &cli.Command{
|
|||||||
}
|
}
|
||||||
subs := rl.GetListeningFilters()
|
subs := rl.GetListeningFilters()
|
||||||
|
|
||||||
log(" %s events stored: %s, subscriptions opened: %s\n", color.HiMagentaString("•"), color.HiMagentaString("%d", totalEvents), color.HiMagentaString("%d", len(subs)))
|
log(" %s events: %s, connections: %s, subscriptions: %s\n",
|
||||||
|
color.HiMagentaString("•"),
|
||||||
|
color.HiMagentaString("%d", totalEvents),
|
||||||
|
color.HiMagentaString("%d", totalConnections.Load()),
|
||||||
|
color.HiMagentaString("%d", len(subs)),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user