Skip to content

Commit 113e9d3

Browse files
committed
Update.
1 parent 565bc17 commit 113e9d3

File tree

8 files changed

+23
-47
lines changed

8 files changed

+23
-47
lines changed

cmd/dashboard/controller/api_v1.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,8 @@ func (v *apiV1) monitorConfigs(c *gin.Context) {
224224
// 获取监控配置列表
225225
if singleton.ServiceSentinelShared != nil {
226226
monitors := singleton.ServiceSentinelShared.Monitors()
227-
log.Printf("API返回监控配置数量: %d", len(monitors))
228-
if len(monitors) > 0 {
229-
for _, monitor := range monitors {
230-
log.Printf("监控配置: ID=%d, Name=%s, Type=%d", monitor.ID, monitor.Name, monitor.Type)
231-
}
232-
}
233227
c.JSON(200, monitors)
234228
} else {
235-
log.Printf("ServiceSentinelShared为nil,返回空数组")
236229
c.JSON(200, []interface{}{})
237230
}
238231
}

cmd/dashboard/controller/common_page.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,9 @@ func (cp *commonPage) network(c *gin.Context) {
195195
// 从监控配置中获取有监控任务的服务器ID
196196
if singleton.ServiceSentinelShared != nil {
197197
monitors := singleton.ServiceSentinelShared.Monitors()
198-
if singleton.Conf.Debug {
199-
log.Printf("network: 找到 %d 个监控配置", len(monitors))
200-
}
201198

202199
for _, monitor := range monitors {
203200
if monitor != nil {
204-
if singleton.Conf.Debug {
205-
log.Printf("network: 处理监控配置 %d: %s", monitor.ID, monitor.Name)
206-
}
207201
// 检查哪些服务器被这个监控任务覆盖
208202
singleton.ServerLock.RLock()
209203
for serverID, server := range singleton.ServerList {
@@ -232,9 +226,6 @@ func (cp *commonPage) network(c *gin.Context) {
232226
}
233227
if !found {
234228
serverIdsWithMonitor = append(serverIdsWithMonitor, serverID)
235-
if singleton.Conf.Debug {
236-
log.Printf("network: 添加服务器 %d (%s) 到监控列表 (Cover=%d)", serverID, server.Name, monitor.Cover)
237-
}
238229
}
239230
// 如果还没有选定ID,或者服务器在线,则将此服务器ID设为当前ID
240231
if id == 0 || server.IsOnline {
@@ -249,10 +240,6 @@ func (cp *commonPage) network(c *gin.Context) {
249240
}
250241
}
251242

252-
if singleton.Conf.Debug {
253-
log.Printf("network: 从监控配置获取到 %d 个有监控任务的服务器", len(serverIdsWithMonitor))
254-
}
255-
256243
// 如果仍然没有找到ID,并且有排序列表,则使用排序列表中的第一个ID
257244
singleton.SortedServerLock.RLock()
258245
if id == 0 && singleton.SortedServerList != nil && len(singleton.SortedServerList) > 0 {
@@ -351,9 +338,6 @@ func (cp *commonPage) network(c *gin.Context) {
351338
var monitorHistories interface{}
352339
if singleton.Conf.DatabaseType == "badger" {
353340
// BadgerDB 模式,查询监控历史记录
354-
if singleton.Conf.Debug {
355-
log.Printf("network: BadgerDB模式,查询监控历史记录")
356-
}
357341

358342
// BadgerDB模式,使用BadgerDB查询监控历史记录
359343
if db.DB != nil && id > 0 {
@@ -376,7 +360,7 @@ func (cp *commonPage) network(c *gin.Context) {
376360
}
377361
}
378362

379-
// 默认显示第一个服务器的ICMP/TCP监控记录
363+
// 显示指定服务器的所有ICMP/TCP监控记录(来自所有监测点)
380364
var filteredHistories []model.MonitorHistory
381365

382366
for _, h := range allHistories {

cmd/dashboard/rpc/rpc.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import (
1616
)
1717

1818
func ServeRPC(port uint) {
19-
// 配置 gRPC 服务器选项,防止 goroutine 泄漏
19+
// 配置 gRPC 服务器选项,防止 goroutine 泄漏和连接问题
2020
opts := []grpc.ServerOption{
21-
// 设置 keepalive 参数,防止僵尸连接
21+
// 优化 keepalive 参数,减少broken pipe错误
2222
grpc.KeepaliveParams(keepalive.ServerParameters{
23-
MaxConnectionIdle: 5 * time.Minute, // 连接空闲5分钟后关闭
24-
MaxConnectionAge: 10 * time.Minute, // 连接最大存活10分钟
25-
MaxConnectionAgeGrace: 30 * time.Second, // 优雅关闭等待30秒
26-
Time: 30 * time.Second, // 每30秒发送keepalive ping
27-
Timeout: 5 * time.Second, // keepalive ping超时5秒
23+
MaxConnectionIdle: 3 * time.Minute, // 减少到3分钟,更快检测断开连接
24+
MaxConnectionAge: 15 * time.Minute, // 增加到15分钟,减少频繁重连
25+
MaxConnectionAgeGrace: 60 * time.Second, // 增加优雅关闭时间到60秒
26+
Time: 20 * time.Second, // 减少到20秒,更频繁的心跳检测
27+
Timeout: 10 * time.Second, // 增加超时到10秒,避免网络抖动
2828
}),
29-
// 设置 keepalive 强制策略
29+
// 优化 keepalive 强制策略
3030
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
31-
MinTime: 10 * time.Second, // 客户端最小keepalive间隔
32-
PermitWithoutStream: true, // 允许没有活跃流时发送keepalive
31+
MinTime: 5 * time.Second, // 减少到5秒,允许更频繁的keepalive
32+
PermitWithoutStream: true, // 允许没有活跃流时发送keepalive
3333
}),
3434
// 设置最大接收消息大小
3535
grpc.MaxRecvMsgSize(4 * 1024 * 1024), // 4MB

resource/template/dashboard-default/monitor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@
6666
<script>
6767
$(".checkbox").checkbox();
6868
</script>
69-
{{end}}
69+
{{end}}

resource/template/theme-default/network.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,12 @@
541541
};
542542
}
543543

544-
// 性能优化:只在数据量适中时才添加markPoint
545-
if (data.length > 5 && data.length < 200) {
544+
// 修复:放宽条件,确保极值标记能够正常显示
545+
if (data.length > 2) {
546546
seriesConfig.markPoint = {
547547
data: [
548-
{ type: 'max', symbol: 'pin', name: 'Max', itemStyle: { color: colors.marker }, symbolSize: 30, label: { fontSize: 8 } },
549-
{ type: 'min', symbol: 'pin', name: 'Min', itemStyle: { color: colors.marker }, symbolSize: 30, label: { fontSize: 8, offset: [0, 7.5] }, symbolRotate: 180 }
548+
{ type: 'max', symbol: 'pin', name: '极高值', itemStyle: { color: colors.marker }, symbolSize: 30, label: { fontSize: 8, show: true } },
549+
{ type: 'min', symbol: 'pin', name: '极低值', itemStyle: { color: colors.marker }, symbolSize: 30, label: { fontSize: 8, offset: [0, 7.5], show: true }, symbolRotate: 180 }
550550
],
551551
z: 3,
552552
zlevel: 0

service/rpc/server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ var ServerHandlerSingleton *ServerHandler
103103
// goroutine 计数器,用于监控 RequestTask goroutine 数量
104104
var (
105105
activeRequestTaskGoroutines int64
106-
maxRequestTaskGoroutines int64 = 200 // 适当提高最大允许的 RequestTask goroutine 数量
106+
maxRequestTaskGoroutines int64 = 50 // 大幅降低最大允许的 RequestTask goroutine 数量
107107
)
108108

109109
type ServerHandler struct {
@@ -279,7 +279,8 @@ func (s *ServerHandler) RequestTask(h *pb.Host, stream pb.ServerService_RequestT
279279
singleton.ServerLock.RUnlock()
280280

281281
// 创建一个带超时的上下文,确保所有goroutine都能正确退出
282-
ctx, cancel := context.WithTimeout(stream.Context(), 2*time.Minute)
282+
// 紧急修复:大幅减少超时时间,防止goroutine堆积
283+
ctx, cancel := context.WithTimeout(stream.Context(), 30*time.Second)
283284
defer cancel()
284285

285286
// 根本修复:不再创建额外的监控goroutine
@@ -304,6 +305,10 @@ func (s *ServerHandler) RequestTask(h *pb.Host, stream pb.ServerService_RequestT
304305
case err := <-closeCh:
305306
// 检查是否为网络连接错误
306307
if isConnectionError(err) {
308+
// 只在Debug模式下记录连接断开日志,减少日志噪音
309+
if singleton.Conf.Debug {
310+
log.Printf("服务器 %d 连接断开: %v", clientID, err)
311+
}
307312
return nil // 将网络连接错误视为正常断开
308313
}
309314
return err

service/singleton/api.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,8 @@ func (m *MonitorAPIService) GetMonitorHistories(search map[string]any) []*model.
534534
}
535535
}
536536

537-
log.Printf("BadgerDB: 为服务器 %d 找到 %d 条监控历史记录", serverID, len(filteredHistories))
538537
return filteredHistories
539538
} else {
540-
log.Printf("BadgerDB未初始化,返回空监控记录")
541539
return make([]*model.MonitorHistory, 0)
542540
}
543541
} else if DB != nil {
@@ -553,7 +551,6 @@ func (m *MonitorAPIService) GetMonitorHistories(search map[string]any) []*model.
553551
}
554552
} else {
555553
// 数据库未初始化,返回空数组
556-
log.Printf("数据库未初始化,返回空监控记录")
557554
return make([]*model.MonitorHistory, 0)
558555
}
559556

service/singleton/singleton.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,12 +2636,9 @@ func StartBadgerMonitorHistoryWorker() {
26362636
err = monitorOps.SaveMonitorHistory(history)
26372637
if err != nil {
26382638
log.Printf("BadgerDB监控历史记录保存失败 (MonitorID: %d): %v", history.MonitorID, err)
2639-
} else {
2640-
log.Printf("BadgerDB监控历史记录保存成功 (MonitorID: %d)", history.MonitorID)
26412639
}
26422640
} else {
26432641
err = fmt.Errorf("BadgerDB未初始化")
2644-
log.Printf("BadgerDB监控历史记录保存失败: %v", err)
26452642
}
26462643

26472644
if req.Callback != nil {

0 commit comments

Comments
 (0)