2023-02-09 20:36:34 +08:00
package msggateway
2021-05-26 19:24:25 +08:00
import (
2023-02-23 19:15:30 +08:00
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
2022-04-05 19:31:35 +08:00
2023-02-23 19:15:30 +08:00
"OpenIM/pkg/statistics"
2022-02-25 19:49:38 +08:00
"fmt"
2021-05-26 19:24:25 +08:00
"sync"
2022-09-12 19:32:24 +08:00
2023-02-23 19:15:30 +08:00
prome "OpenIM/pkg/common/prome"
2022-09-12 19:32:24 +08:00
"github.com/go-playground/validator/v10"
2021-05-26 19:24:25 +08:00
)
var (
2022-05-09 18:23:06 +08:00
rwLock * sync . RWMutex
validate * validator . Validate
ws WServer
rpcSvr RPCServer
sendMsgAllCount uint64
sendMsgFailedCount uint64
sendMsgSuccessCount uint64
userCount uint64
2022-05-18 11:52:15 +08:00
sendMsgAllCountLock sync . RWMutex
2021-05-26 19:24:25 +08:00
)
func Init ( rpcPort , wsPort int ) {
rwLock = new ( sync . RWMutex )
validate = validator . New ( )
2022-05-09 18:23:06 +08:00
statistics . NewStatistics ( & sendMsgAllCount , config . Config . ModuleName . LongConnSvrName , fmt . Sprintf ( "%d second recv to msg_gateway sendMsgCount" , constant . StatisticsTimeInterval ) , constant . StatisticsTimeInterval )
statistics . NewStatistics ( & userCount , config . Config . ModuleName . LongConnSvrName , fmt . Sprintf ( "%d second add user conn" , constant . StatisticsTimeInterval ) , constant . StatisticsTimeInterval )
2021-05-26 19:24:25 +08:00
ws . onInit ( wsPort )
rpcSvr . onInit ( rpcPort )
2022-09-15 12:07:28 +08:00
initPrometheus ( )
2021-05-26 19:24:25 +08:00
}
2023-02-22 19:51:14 +08:00
func Run ( prometheusPort int ) {
2021-05-26 19:24:25 +08:00
go ws . run ( )
go rpcSvr . run ( )
2022-09-12 19:32:24 +08:00
go func ( ) {
2023-02-24 11:13:16 +08:00
err := prome . StartPrometheusSrv ( prometheusPort )
2022-09-12 19:32:24 +08:00
if err != nil {
panic ( err )
}
} ( )
2021-05-26 19:24:25 +08:00
}