feat 自定义拦截器
This commit is contained in:
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.24.0
|
||||
|
||||
require (
|
||||
bou.ke/monkey v1.0.2
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116143417-d944729ad0e5
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116155014-3de703eb83c5
|
||||
github.com/alicebob/miniredis/v2 v2.35.0
|
||||
github.com/gin-contrib/cors v1.7.6
|
||||
github.com/gin-gonic/gin v1.11.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -2,8 +2,8 @@ bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI=
|
||||
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116143417-d944729ad0e5 h1:gkPNZ/OiXQhtiqRMdLrL5Zw580zgb9082jkZQqP71Fk=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116143417-d944729ad0e5/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116155014-3de703eb83c5 h1:b7pTgEyYUKpHtAAt4ea/3EYfX0Y0lYwhjrgf3kTyn0w=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260116155014-3de703eb83c5/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
|
||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
|
||||
|
||||
@@ -7,13 +7,20 @@ import (
|
||||
|
||||
var (
|
||||
OnlineUsersGauge prometheus.Gauge
|
||||
FlowCounter prometheus.Counter
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.Infof("Init prometheus metric...")
|
||||
OnlineUsersGauge = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "online_users",
|
||||
Name: "gateway_online_users",
|
||||
Help: "Total number of online users",
|
||||
})
|
||||
prometheus.MustRegister(OnlineUsersGauge)
|
||||
|
||||
FlowCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "gateway_flow_counter",
|
||||
Help: "Total number of flow",
|
||||
})
|
||||
prometheus.MustRegister(FlowCounter)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/handler/ws_handler/client"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"sync"
|
||||
@@ -39,8 +40,10 @@ func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
|
||||
log.Errorf("ToClient proto.Marshal error: %v", err)
|
||||
continue
|
||||
}
|
||||
dataLen := float64(len(data))
|
||||
for _, cli := range client.UserMgr.GetAll() {
|
||||
cli.WriteBytesPreMarshal(data)
|
||||
global.FlowCounter.Add(dataLen)
|
||||
}
|
||||
|
||||
//for _, client := range ws_handler.UserMgr.GetAll() {
|
||||
@@ -49,6 +52,7 @@ func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
|
||||
} else {
|
||||
if cli := client.UserMgr.GetByUSN(args.USN); cli != nil {
|
||||
cli.WriteBytes(ss_pb.MessageID(args.MessageID), args.Payload)
|
||||
global.FlowCounter.Add(float64(len(args.Payload)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,16 @@ func NewServer(ttl int64) *Server {
|
||||
EtcdTTL: ttl,
|
||||
},
|
||||
}
|
||||
s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption
|
||||
s.Base.OnInit = s.OnInit
|
||||
s.Base.OnClose = s.OnClose
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Server) OnCustomGrpcServerOption() []grpc.ServerOption {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) OnInit(serve *grpc.Server) {
|
||||
client.GatewaySID = s.SID
|
||||
grpc_pb.RegisterGatewayServer(serve, s)
|
||||
|
||||
Reference in New Issue
Block a user