mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
parent
b484fe53f0
commit
68e3bb00e4
@ -120,6 +120,7 @@ func main() {
|
|||||||
singleton.CleanServiceHistory()
|
singleton.CleanServiceHistory()
|
||||||
serviceSentinelDispatchBus := make(chan model.Service) // 用于传递服务监控任务信息的channel
|
serviceSentinelDispatchBus := make(chan model.Service) // 用于传递服务监控任务信息的channel
|
||||||
go rpc.DispatchTask(serviceSentinelDispatchBus)
|
go rpc.DispatchTask(serviceSentinelDispatchBus)
|
||||||
|
go rpc.DispatchKeepalive()
|
||||||
go singleton.AlertSentinelStart()
|
go singleton.AlertSentinelStart()
|
||||||
singleton.NewServiceSentinel(serviceSentinelDispatchBus)
|
singleton.NewServiceSentinel(serviceSentinelDispatchBus)
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/keepalive"
|
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"google.golang.org/grpc/peer"
|
"google.golang.org/grpc/peer"
|
||||||
|
|
||||||
@ -22,14 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ServeRPC() *grpc.Server {
|
func ServeRPC() *grpc.Server {
|
||||||
server := grpc.NewServer(grpc.KeepaliveEnforcementPolicy(
|
server := grpc.NewServer(grpc.ChainUnaryInterceptor(getRealIp, waf))
|
||||||
keepalive.EnforcementPolicy{
|
|
||||||
MinTime: time.Second * 20,
|
|
||||||
PermitWithoutStream: true,
|
|
||||||
}), grpc.KeepaliveParams(
|
|
||||||
keepalive.ServerParameters{
|
|
||||||
Time: time.Second * 30,
|
|
||||||
}), grpc.ChainUnaryInterceptor(getRealIp, waf))
|
|
||||||
rpcService.NezhaHandlerSingleton = rpcService.NewNezhaHandler()
|
rpcService.NezhaHandlerSingleton = rpcService.NewNezhaHandler()
|
||||||
proto.RegisterNezhaServiceServer(server, rpcService.NezhaHandlerSingleton)
|
proto.RegisterNezhaServiceServer(server, rpcService.NezhaHandlerSingleton)
|
||||||
return server
|
return server
|
||||||
@ -124,6 +116,20 @@ func DispatchTask(serviceSentinelDispatchBus <-chan model.Service) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DispatchKeepalive() {
|
||||||
|
singleton.Cron.AddFunc("@every 60s", func() {
|
||||||
|
singleton.SortedServerLock.RLock()
|
||||||
|
defer singleton.SortedServerLock.RUnlock()
|
||||||
|
for i := 0; i < len(singleton.SortedServerList); i++ {
|
||||||
|
if singleton.SortedServerList[i] == nil || singleton.SortedServerList[i].TaskStream == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
singleton.SortedServerList[i].TaskStream.Send(&proto.Task{Type: model.TaskTypeKeepalive})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func ServeNAT(w http.ResponseWriter, r *http.Request, natConfig *model.NAT) {
|
func ServeNAT(w http.ResponseWriter, r *http.Request, natConfig *model.NAT) {
|
||||||
singleton.ServerLock.RLock()
|
singleton.ServerLock.RLock()
|
||||||
server := singleton.ServerList[natConfig.ServerID]
|
server := singleton.ServerList[natConfig.ServerID]
|
||||||
|
@ -19,7 +19,7 @@ const (
|
|||||||
TaskTypeCommand
|
TaskTypeCommand
|
||||||
TaskTypeTerminal
|
TaskTypeTerminal
|
||||||
TaskTypeUpgrade
|
TaskTypeUpgrade
|
||||||
TaskTypeKeepaliveDeprecated
|
TaskTypeKeepalive
|
||||||
TaskTypeTerminalGRPC
|
TaskTypeTerminalGRPC
|
||||||
TaskTypeNAT
|
TaskTypeNAT
|
||||||
TaskTypeReportHostInfo
|
TaskTypeReportHostInfo
|
||||||
|
Loading…
Reference in New Issue
Block a user