This commit is contained in:
wangchuxiao
2022-09-15 01:22:20 +08:00
parent 266a2b4c76
commit a1f79f4508
13 changed files with 187 additions and 26 deletions
+7 -16
View File
@@ -6,6 +6,7 @@ import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/kafka"
"Open_IM/pkg/common/log"
promePkg "Open_IM/pkg/common/prometheus"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
"Open_IM/pkg/proto/msg"
"Open_IM/pkg/utils"
@@ -13,16 +14,9 @@ import (
"strconv"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"google.golang.org/grpc"
)
var (
sendMsgSuccessCounter prometheus.Counter
sendMsgFailedCounter prometheus.Counter
)
type rpcChat struct {
rpcPort int
rpcRegisterName string
@@ -55,14 +49,7 @@ func NewRpcChatServer(port int) *rpcChat {
}
func (rpc *rpcChat) initPrometheus() {
sendMsgSuccessCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "send_msg_success",
Help: "The number of send msg success",
})
sendMsgFailedCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "send_msg_failed",
Help: "The number of send msg failed",
})
promePkg.NewSendMsgCount()
}
func (rpc *rpcChat) Run() {
@@ -80,7 +67,11 @@ func (rpc *rpcChat) Run() {
}
log.Info("", "listen network success, address ", address)
srv := grpc.NewServer()
var grpcOpts []grpc.ServerOption
if config.Config.Prometheus.Enable {
grpcOpts = append(grpcOpts, promePkg.UnaryServerInterceptorProme)
}
srv := grpc.NewServer(grpcOpts...)
defer srv.GracefulStop()
rpcRegisterIP := config.Config.RpcRegisterIP