2021-05-26 19:24:25 +08:00
package gate
import (
2021-10-11 22:12:01 +08:00
"Open_IM/pkg/common/config"
2022-05-09 18:23:06 +08:00
"Open_IM/pkg/common/constant"
2022-04-05 19:31:35 +08:00
2022-02-25 19:49:38 +08:00
"Open_IM/pkg/statistics"
"fmt"
2021-05-26 19:24:25 +08:00
"sync"
2022-09-12 19:32:24 +08:00
promePkg "Open_IM/pkg/common/prometheus"
"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
}
2022-09-12 19:32:24 +08:00
func Run ( promethuesPort 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 ( ) {
err := promePkg . StartPromeSrv ( promethuesPort )
if err != nil {
panic ( err )
}
} ( )
2021-05-26 19:24:25 +08:00
}