mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-09 22:17:27 +08:00
Add GRPC and gin server monitoring logic3
This commit is contained in:
parent
e6adaa7cda
commit
8e50fe8bfe
@ -44,11 +44,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(port int) error {
|
func run(port int, proPort int) error {
|
||||||
log.ZInfo(context.Background(), "Openim api port:", "port", port)
|
log.ZInfo(context.Background(), "Openim api port:", "port", port)
|
||||||
|
|
||||||
if port == 0 {
|
if port == 0 || proPort == 0 {
|
||||||
err := "port is empty"
|
err := "port or proPort is empty:" + strconv.Itoa(port) + "," + strconv.Itoa(proPort)
|
||||||
log.ZError(context.Background(), err, nil)
|
log.ZError(context.Background(), err, nil)
|
||||||
|
|
||||||
return fmt.Errorf(err)
|
return fmt.Errorf(err)
|
||||||
@ -85,7 +85,8 @@ func run(port int) error {
|
|||||||
router := api.NewGinRouter(client, rdb)
|
router := api.NewGinRouter(client, rdb)
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
p := ginProm.NewPrometheus("app", prom_metrics.G_api_metrics.MetricList())
|
p := ginProm.NewPrometheus("app", prom_metrics.G_api_metrics.MetricList())
|
||||||
p.SetListenAddress(":90")
|
|
||||||
|
p.SetListenAddress(fmt.Sprintf(":%d", proPort))
|
||||||
p.Use(router)
|
p.Use(router)
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
log.ZInfo(context.Background(), "api init router success")
|
log.ZInfo(context.Background(), "api init router success")
|
||||||
|
|||||||
@ -384,6 +384,7 @@ callback:
|
|||||||
# The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh
|
# The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh
|
||||||
prometheus:
|
prometheus:
|
||||||
enable: true
|
enable: true
|
||||||
|
apiPrometheusPort: [20100]
|
||||||
userPrometheusPort: [ 20110 ]
|
userPrometheusPort: [ 20110 ]
|
||||||
friendPrometheusPort: [ 20120 ]
|
friendPrometheusPort: [ 20120 ]
|
||||||
messagePrometheusPort: [ 20130 ]
|
messagePrometheusPort: [ 20130 ]
|
||||||
|
|||||||
@ -383,6 +383,7 @@ callback:
|
|||||||
# The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh
|
# The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh
|
||||||
prometheus:
|
prometheus:
|
||||||
enable: ${PROMETHEUS_ENABLE}
|
enable: ${PROMETHEUS_ENABLE}
|
||||||
|
apiPrometheusPort: [${API_PROM_PORT}]
|
||||||
userPrometheusPort: [ ${USER_PROM_PORT} ]
|
userPrometheusPort: [ ${USER_PROM_PORT} ]
|
||||||
friendPrometheusPort: [ ${FRIEND_PROM_PORT} ]
|
friendPrometheusPort: [ ${FRIEND_PROM_PORT} ]
|
||||||
messagePrometheusPort: [ ${MESSAGE_PROM_PORT} ]
|
messagePrometheusPort: [ ${MESSAGE_PROM_PORT} ]
|
||||||
|
|||||||
@ -69,9 +69,10 @@ func (s *Server) SetLongConnServer(LongConnServer LongConnServer) {
|
|||||||
s.LongConnServer = LongConnServer
|
s.LongConnServer = LongConnServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(rpcPort int, longConnServer LongConnServer) *Server {
|
func NewServer(rpcPort int, proPort int, longConnServer LongConnServer) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
rpcPort: rpcPort,
|
rpcPort: rpcPort,
|
||||||
|
prometheusPort: proPort,
|
||||||
LongConnServer: longConnServer,
|
LongConnServer: longConnServer,
|
||||||
pushTerminal: []int{constant.IOSPlatformID, constant.AndroidPlatformID},
|
pushTerminal: []int{constant.IOSPlatformID, constant.AndroidPlatformID},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
hubServer := NewServer(rpcPort, longServer)
|
hubServer := NewServer(rpcPort, prometheusPort, longServer)
|
||||||
go func() {
|
go func() {
|
||||||
err := hubServer.Start()
|
err := hubServer.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -32,9 +32,9 @@ func NewApiCmd() *ApiCmd {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ApiCmd) AddApi(f func(port int) error) {
|
func (a *ApiCmd) AddApi(f func(port int, promPort int) error) {
|
||||||
a.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
a.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
return f(a.getPortFlag(cmd))
|
return f(a.getPortFlag(cmd), a.getPrometheusPortFlag(cmd))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ func (a *ApiCmd) GetPortFromConfig(portType string) int {
|
|||||||
fmt.Println("GetPortFromConfig:", portType)
|
fmt.Println("GetPortFromConfig:", portType)
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.Api.OpenImApiPort[0]
|
return config2.Config.Api.OpenImApiPort[0]
|
||||||
} else {
|
} else if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.ApiPrometheusPort[0]
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,7 +62,7 @@ func (m *MsgGatewayCmd) GetPortFromConfig(portType string) int {
|
|||||||
} else if portType == constant.FlagPort {
|
} else if portType == constant.FlagPort {
|
||||||
return config2.Config.LongConnSvr.OpenImMessageGatewayPort[0]
|
return config2.Config.LongConnSvr.OpenImMessageGatewayPort[0]
|
||||||
} else if portType == constant.FlagPrometheusPort {
|
} else if portType == constant.FlagPrometheusPort {
|
||||||
return 0
|
return config2.Config.Prometheus.MessageGatewayPrometheusPort[0]
|
||||||
} else {
|
} else {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,34 +59,58 @@ func (a *RpcCmd) GetPortFromConfig(portType string) int {
|
|||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImPushPort[0]
|
return config2.Config.RpcPort.OpenImPushPort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.PushPrometheusPort[0]
|
||||||
|
}
|
||||||
case RpcAuthServer:
|
case RpcAuthServer:
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImAuthPort[0]
|
return config2.Config.RpcPort.OpenImAuthPort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.AuthPrometheusPort[0]
|
||||||
|
}
|
||||||
case RpcConversationServer:
|
case RpcConversationServer:
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImConversationPort[0]
|
return config2.Config.RpcPort.OpenImConversationPort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.ConversationPrometheusPort[0]
|
||||||
|
}
|
||||||
case RpcFriendServer:
|
case RpcFriendServer:
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImFriendPort[0]
|
return config2.Config.RpcPort.OpenImFriendPort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.FriendPrometheusPort[0]
|
||||||
|
}
|
||||||
case RpcGroupServer:
|
case RpcGroupServer:
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImGroupPort[0]
|
return config2.Config.RpcPort.OpenImGroupPort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.GroupPrometheusPort[0]
|
||||||
|
}
|
||||||
case RpcMsgServer:
|
case RpcMsgServer:
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImMessagePort[0]
|
return config2.Config.RpcPort.OpenImMessagePort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.MessagePrometheusPort[0]
|
||||||
|
}
|
||||||
case RpcThirdServer:
|
case RpcThirdServer:
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImThirdPort[0]
|
return config2.Config.RpcPort.OpenImThirdPort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.ThirdPrometheusPort[0]
|
||||||
|
}
|
||||||
case RpcUserServer:
|
case RpcUserServer:
|
||||||
if portType == constant.FlagPort {
|
if portType == constant.FlagPort {
|
||||||
return config2.Config.RpcPort.OpenImUserPort[0]
|
return config2.Config.RpcPort.OpenImUserPort[0]
|
||||||
}
|
}
|
||||||
|
if portType == constant.FlagPrometheusPort {
|
||||||
|
return config2.Config.Prometheus.UserPrometheusPort[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@ -263,6 +263,7 @@ type configStruct struct {
|
|||||||
|
|
||||||
Prometheus struct {
|
Prometheus struct {
|
||||||
Enable bool `yaml:"enable"`
|
Enable bool `yaml:"enable"`
|
||||||
|
ApiPrometheusPort []int `yaml:"apiPrometheusPort"`
|
||||||
UserPrometheusPort []int `yaml:"userPrometheusPort"`
|
UserPrometheusPort []int `yaml:"userPrometheusPort"`
|
||||||
FriendPrometheusPort []int `yaml:"friendPrometheusPort"`
|
FriendPrometheusPort []int `yaml:"friendPrometheusPort"`
|
||||||
MessagePrometheusPort []int `yaml:"messagePrometheusPort"`
|
MessagePrometheusPort []int `yaml:"messagePrometheusPort"`
|
||||||
|
|||||||
@ -335,6 +335,8 @@ def "IOS_PRODUCTION" "false" # IOS生产
|
|||||||
|
|
||||||
###################### Prometheus 配置信息 ######################
|
###################### Prometheus 配置信息 ######################
|
||||||
def "PROMETHEUS_ENABLE" "false" # 是否启用 Prometheus
|
def "PROMETHEUS_ENABLE" "false" # 是否启用 Prometheus
|
||||||
|
# Api 服务的 Prometheus 端口
|
||||||
|
readonly API_PROM_PORT=${API_PROM_PORT:-'20110'}
|
||||||
# User 服务的 Prometheus 端口
|
# User 服务的 Prometheus 端口
|
||||||
readonly USER_PROM_PORT=${USER_PROM_PORT:-'20110'}
|
readonly USER_PROM_PORT=${USER_PROM_PORT:-'20110'}
|
||||||
# Friend 服务的 Prometheus 端口
|
# Friend 服务的 Prometheus 端口
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user