mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-04 12:03:43 +02:00
internal/server/server.go: count number of connections and send a log message in OnTick()
This commit is contained in:
parent
1db04c0e76
commit
1f22435dfa
1 changed files with 14 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
||||||
|
|
@ -17,6 +18,7 @@ type Server struct {
|
||||||
|
|
||||||
addr string
|
addr string
|
||||||
eng gnet.Engine
|
eng gnet.Engine
|
||||||
|
num_conn uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(addr string) *Server {
|
func New(addr string) *Server {
|
||||||
|
|
@ -34,6 +36,11 @@ func (s *Server) OnBoot(eng gnet.Engine) gnet.Action {
|
||||||
return gnet.None
|
return gnet.None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) OnOpen(c gnet.Conn) ([]byte, gnet.Action) {
|
||||||
|
atomic.AddUint64(&s.num_conn, 1)
|
||||||
|
return nil, gnet.None
|
||||||
|
}
|
||||||
|
|
||||||
// OnShutdown callback function
|
// OnShutdown callback function
|
||||||
//
|
//
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
@ -45,7 +52,11 @@ func (s *Server) OnShutdown(eng gnet.Engine) {
|
||||||
//
|
//
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
func (s *Server) OnTick() (time.Duration, gnet.Action) {
|
func (s *Server) OnTick() (time.Duration, gnet.Action) {
|
||||||
log.Info("Server info", "connections", s.eng.CountConnections())
|
log.Info("Server info", log.Ctx{
|
||||||
|
"connections": atomic.LoadUint64(&s.num_conn),
|
||||||
|
"current_connections": s.eng.CountConnections(),
|
||||||
|
})
|
||||||
|
atomic.StoreUint64(&s.num_conn, 0)
|
||||||
return time.Second * 10, gnet.None
|
return time.Second * 10, gnet.None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue