From e6adaa7cda9496f7aae5ebe5036b2d68dafcb267 Mon Sep 17 00:00:00 2001 From: "lin.huang" Date: Mon, 30 Oct 2023 20:16:34 +0800 Subject: [PATCH] Add GRPC and gin server monitoring logic2 --- config/config.yaml | 2 +- pkg/common/startrpc/start.go | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 0f980b4e4..df242b326 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -383,7 +383,7 @@ callback: # The number of Prometheus ports per service needs to correspond to rpcPort # The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh prometheus: - enable: false + enable: true userPrometheusPort: [ 20110 ] friendPrometheusPort: [ 20120 ] messagePrometheusPort: [ 20130 ] diff --git a/pkg/common/startrpc/start.go b/pkg/common/startrpc/start.go index bba43074b..fed7c521d 100644 --- a/pkg/common/startrpc/start.go +++ b/pkg/common/startrpc/start.go @@ -100,7 +100,7 @@ func Start( go func() { if config.Config.Prometheus.Enable && prometheusPort != 0 { // Create a HTTP server for prometheus. - httpServer := &http.Server{Handler: promhttp.HandlerFor(reg, promhttp.HandlerOpts{}), Addr: fmt.Sprintf("0.0.0.0:%d", 90)} + httpServer := &http.Server{Handler: promhttp.HandlerFor(reg, promhttp.HandlerOpts{}), Addr: fmt.Sprintf("0.0.0.0:%d", getPromPort(rpcRegisterName))} if err := httpServer.ListenAndServe(); err != nil { log.Fatal("Unable to start a http server.") } @@ -109,3 +109,28 @@ func Start( return utils.Wrap1(srv.Serve(listener)) } +func getPromPort(name string) int { + switch name { + case "MessageGateway": + return config.Config.Prometheus.MessageGatewayPrometheusPort[0] + case "User": + return config.Config.Prometheus.UserPrometheusPort[0] + case "Msg": + return config.Config.Prometheus.MessagePrometheusPort[0] + case "Conversation": + return config.Config.Prometheus.ConversationPrometheusPort[0] + case "Friend": + return config.Config.Prometheus.FriendPrometheusPort[0] + case "Push": + return config.Config.Prometheus.PushPrometheusPort[0] + case "Group": + return config.Config.Prometheus.GroupPrometheusPort[0] + case "Auth": + return config.Config.Prometheus.AuthPrometheusPort[0] + case "Third": + return config.Config.Prometheus.ThirdPrometheusPort[0] + default: + fmt.Println("name not have correct prometheus port!!!") + return 9090 + } +}