Skip to content

Commit 452ee78

Browse files
committed
Bug fix.
1 parent 84b3743 commit 452ee78

5 files changed

Lines changed: 5 additions & 96 deletions

File tree

cmd/dashboard/controller/api_v1.go

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ func (v *apiV1) serve() {
8787
mr.GET("/configs", v.monitorConfigs)
8888
mr.GET("/:id", v.monitorHistoriesById)
8989

90-
sr := v.r.Group("service")
91-
sr.Use(mygin.Authorize(mygin.AuthorizeOption{
92-
MemberOnly: false,
93-
IsPage: false,
94-
}))
95-
sr.Use(mygin.ValidateViewPassword(mygin.ValidateViewPasswordOption{
96-
IsPage: false,
97-
AbortWhenFail: true,
98-
}))
99-
sr.GET("", v.serviceStatus)
10090

10191
// Frontend Profile API (提供原先由 CommonEnvironment 注入的全局配置)
10292
cr := v.r.Group("profile")
@@ -834,80 +824,3 @@ func monitoredServerIDs(monitors []*model.Monitor) []uint64 {
834824
return result
835825
}
836826

837-
func (v *apiV1) serviceStatus(c *gin.Context) {
838-
type serviceItem struct {
839-
ID uint64 `json:"ID"`
840-
Monitor *model.Monitor `json:"Monitor"`
841-
CurrentUp uint64 `json:"CurrentUp"`
842-
CurrentDown uint64 `json:"CurrentDown"`
843-
TotalUp uint64 `json:"TotalUp"`
844-
TotalDown uint64 `json:"TotalDown"`
845-
Uptime float32 `json:"Uptime"`
846-
Delay []float32 `json:"Delay"`
847-
Up []int `json:"Up"`
848-
Down []int `json:"Down"`
849-
}
850-
851-
items := make([]serviceItem, 0)
852-
if singleton.ServiceSentinelShared != nil {
853-
singleton.AlertsLock.RLock()
854-
stats := singleton.ServiceSentinelShared.LoadStats()
855-
for id, item := range stats {
856-
if item == nil || item.Monitor == nil || !item.Monitor.EnableShowInService {
857-
continue
858-
}
859-
total := item.TotalUp + item.TotalDown
860-
uptime := float32(0)
861-
if total > 0 {
862-
uptime = float32(item.TotalUp) / float32(total) * 100
863-
}
864-
items = append(items, serviceItem{
865-
ID: id,
866-
Monitor: item.Monitor,
867-
CurrentUp: item.CurrentUp,
868-
CurrentDown: item.CurrentDown,
869-
TotalUp: item.TotalUp,
870-
TotalDown: item.TotalDown,
871-
Uptime: uptime,
872-
Delay: float32Array(item.Delay),
873-
Up: intArray(item.Up),
874-
Down: intArray(item.Down),
875-
})
876-
}
877-
singleton.AlertsLock.RUnlock()
878-
}
879-
880-
sort.Slice(items, func(i, j int) bool {
881-
if items[i].Monitor == nil || items[j].Monitor == nil {
882-
return items[i].ID < items[j].ID
883-
}
884-
if items[i].Monitor.Name == items[j].Monitor.Name {
885-
return items[i].ID < items[j].ID
886-
}
887-
return items[i].Monitor.Name < items[j].Monitor.Name
888-
})
889-
890-
WriteJSON(c, 200, gin.H{"Services": items})
891-
}
892-
893-
func float32Array(input *[30]float32) []float32 {
894-
if input == nil {
895-
return []float32{}
896-
}
897-
output := make([]float32, 0, len(input))
898-
for _, value := range input {
899-
output = append(output, value)
900-
}
901-
return output
902-
}
903-
904-
func intArray(input *[30]int) []int {
905-
if input == nil {
906-
return []int{}
907-
}
908-
output := make([]int, 0, len(input))
909-
for _, value := range input {
910-
output = append(output, value)
911-
}
912-
return output
913-
}

cmd/dashboard/controller/member_api.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,6 @@ type monitorForm struct {
837837
MaxLatency float32
838838
LatencyNotify string
839839
EnableTriggerTask string
840-
EnableShowInService string
841840
FailTriggerTasksRaw string
842841
RecoverTriggerTasksRaw string
843842
}
@@ -868,7 +867,6 @@ func (ma *memberAPI) addOrEditMonitor(c *gin.Context) {
868867
m.LatencyNotify = mf.LatencyNotify == "on"
869868
m.MinLatency = mf.MinLatency
870869
m.MaxLatency = mf.MaxLatency
871-
m.EnableShowInService = mf.EnableShowInService == "on"
872870
m.EnableTriggerTask = mf.EnableTriggerTask == "on"
873871
m.RecoverTriggerTasksRaw = mf.RecoverTriggerTasksRaw
874872
m.FailTriggerTasksRaw = mf.FailTriggerTasksRaw

db/badger.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,20 @@ func (b *BadgerDB) startMaintenance() {
222222
}()
223223

224224
// 智能维护:结合缓存监控和内存优化
225-
ticker := time.NewTicker(10 * time.Minute) // 10分钟间隔
225+
ticker := time.NewTicker(5 * time.Minute) // 5分钟间隔
226226
cacheTicker := time.NewTicker(5 * time.Minute) // 5分钟缓存检查
227227
defer ticker.Stop()
228228
defer cacheTicker.Stop()
229229

230230
for {
231231
select {
232232
case <-ticker.C:
233-
// 值日志GC - 单次周期内尝试多轮回收,提升清理效果
234-
_, _, err := b.RunValueLogGCWithStats(0.7, 3)
233+
// 值日志GC - 更加激进:降至0.4阈值,每次最多20轮,为了解决日志文件无限堆积的问题
234+
rounds, _, err := b.RunValueLogGCWithStats(0.4, 20)
235235
if err != nil {
236236
log.Printf("Value log GC failed: %v", err)
237+
} else if rounds > 0 {
238+
log.Printf("Value log GC 成功执行了 %d 轮清理", rounds)
237239
}
238240

239241
case <-cacheTicker.C:
@@ -1223,7 +1225,6 @@ func convertDbFieldTypes(data *map[string]interface{}, rawJSON []byte) {
12231225
"HideForGuest", "EnableDDNS", "enable_ddns",
12241226
// Monitor fields
12251227
"notify", "Notify", "enable_trigger_task", "EnableTriggerTask",
1226-
"enable_show_in_service", "EnableShowInService",
12271228
"latency_notify", "LatencyNotify",
12281229
// User fields
12291230
"hireable", "Hireable", "super_admin", "SuperAdmin",

frontend/src/admin/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ const entityConfigs: Partial<Record<AdminKey, EntityConfig>> = {
159159
{ label: '间隔', render: (row) => `${escapeHtml(value(row, 'Duration'))}s` },
160160
{ label: '通知组', render: (row) => badge(value(row, 'NotificationTag') || 'default') },
161161
{ label: '通知', render: (row) => enabled(get(row, 'Notify')) },
162-
{ label: '服务页', render: (row) => enabled(get(row, 'EnableShowInService')) },
163162
{ label: '触发任务', render: (row) => triggerTasksMarkup(row) },
164163
{ label: '操作', className: 'is-actions', render: (row) => actionButtons('monitor', row) },
165164
],
@@ -175,7 +174,6 @@ const entityConfigs: Partial<Record<AdminKey, EntityConfig>> = {
175174
checkboxField('LatencyNotify', '启用延迟通知'),
176175
numberField('MinLatency', '最小延迟阈值', 0),
177176
numberField('MaxLatency', '最大延迟阈值', 0),
178-
checkboxField('EnableShowInService', '显示在服务页'),
179177
checkboxField('EnableTriggerTask', '启用触发任务'),
180178
relationField('SkipServersRaw', '服务器范围列表', 'server', true),
181179
relationField('FailTriggerTasksRaw', '失败触发任务', 'cron', true, triggerTaskFilter),

model/monitor.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ type Monitor struct {
5656
Cover uint8
5757

5858
EnableTriggerTask bool `gorm:"default: false"`
59-
EnableShowInService bool `gorm:"default: false"`
6059
FailTriggerTasksRaw string `gorm:"default:'[]'"`
6160
RecoverTriggerTasksRaw string `gorm:"default:'[]'"`
6261
FailTriggerTasks []uint64 `gorm:"-" json:"-"` // 失败时执行的触发任务id

0 commit comments

Comments
 (0)