feat(ops): 添加分组和账号级别监控指标

- 后端新增 GetAccountAvailability 方法获取账号可用性数据
- 添加分组可用率和限流率计算辅助函数
- 前端支持分组和账号级别的监控指标类型
- 优化警报规则指标选择器,按类别分组显示
This commit is contained in:
IanShaw027
2026-01-11 20:33:52 +08:00
parent c1a3dd41dd
commit dd59e872ff
5 changed files with 126 additions and 11 deletions

View File

@@ -838,3 +838,38 @@ func (l *slidingWindowLimiter) Allow(now time.Time) bool {
l.sent = append(l.sent, now)
return true
}
// computeGroupAvailableRatio returns the available percentage for a group.
// Formula: (AvailableCount / TotalAccounts) * 100.
// Returns 0 when TotalAccounts is 0.
func computeGroupAvailableRatio(group *GroupAvailability) float64 {
if group == nil || group.TotalAccounts <= 0 {
return 0
}
return (float64(group.AvailableCount) / float64(group.TotalAccounts)) * 100
}
// computeGroupRateLimitRatio returns the rate-limited percentage for a group.
// Formula: (RateLimitCount / TotalAccounts) * 100.
// Returns 0 when TotalAccounts is 0.
func computeGroupRateLimitRatio(group *GroupAvailability) float64 {
if group == nil || group.TotalAccounts <= 0 {
return 0
}
return (float64(group.RateLimitCount) / float64(group.TotalAccounts)) * 100
}
// countAccountsByCondition counts accounts that satisfy the given condition.
// It iterates over accounts and applies the predicate to each entry.
func countAccountsByCondition(accounts map[int64]*AccountAvailability, condition func(*AccountAvailability) bool) int64 {
if len(accounts) == 0 || condition == nil {
return 0
}
var count int64
for _, account := range accounts {
if account != nil && condition(account) {
count++
}
}
return count
}