Documentation ¶
Index ¶
- Constants
- Variables
- func AddNotificationToList(n *model.Notification)
- func AlertSentinelStart()
- func CleanMonitorHistory()
- func CronTrigger(cr model.Cron) func()
- func GetStatusCode[T float32 | uint64](percent T) int
- func IPDesensitize(ip string) string
- func Init()
- func InitAPI()
- func InitConfigFromPath(path string)
- func InitCronTask()
- func InitDBFromPath(path string)
- func InitLocalizer()
- func InitNotification()
- func InitServer()
- func LoadAPI()
- func LoadCronTasks()
- func LoadNotifications()
- func LoadServers()
- func LoadSingleton()
- func ManualTrigger(c model.Cron)
- func NewServiceSentinel(serviceSentinelDispatchBus chan<- model.Monitor)
- func OnDeleteAlert(id uint64)
- func OnDeleteNotification(id uint64)
- func OnRefreshOrAddAlert(alert model.AlertRule)
- func OnRefreshOrAddNotification(n *model.Notification)
- func ReSortServer()
- func RecordTransferHourlyUsage()
- func SendNotification(notificationTag string, desc string, mutable bool, ext ...*model.Server)
- func SetDefaultNotificationTagInDB(n *model.Notification)
- func StatusCodeToString(statusCode int) string
- func UpdateNotificationInList(n *model.Notification)
- type CommonResponse
- type CommonServerInfo
- type NotificationHistory
- type ReportData
- type ServerAPIService
- func (s *ServerAPIService) GetAllList() *ServerInfoResponse
- func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse
- func (s *ServerAPIService) GetListByTag(tag string) *ServerInfoResponse
- func (s *ServerAPIService) GetStatusByIDList(idList []uint64) *ServerStatusResponse
- func (s *ServerAPIService) GetStatusByTag(tag string) *ServerStatusResponse
- type ServerInfoResponse
- type ServerStatusResponse
- type ServiceSentinel
- func (ss *ServiceSentinel) Dispatch(r ReportData)
- func (ss *ServiceSentinel) LoadStats() map[uint64]*model.ServiceItemResponse
- func (ss *ServiceSentinel) Monitors() []*model.Monitor
- func (ss *ServiceSentinel) OnMonitorDelete(id uint64)
- func (ss *ServiceSentinel) OnMonitorUpdate(m model.Monitor) error
- type StatusResponse
Constants ¶
const ( StatusNoData StatusGood StatusLowAvailability StatusDown )
Variables ¶
var ( AlertsLock sync.RWMutex Alerts []*model.AlertRule AlertsCycleTransferStatsStore map[uint64]*model.CycleTransferStats // [alert_id] -> 对应报警规则的周期流量统计 )
报警规则
var ( ApiTokenList = make(map[string]*model.ApiToken) UserIDToApiTokenList = make(map[uint64][]string) ApiLock sync.RWMutex ServerAPI = &ServerAPIService{} )
var ( Cron *cron.Cron Crons map[uint64]*model.Cron // [CrondID] -> *model.Cron CronLock sync.RWMutex )
var ( NotificationList map[string]map[uint64]*model.Notification // [NotificationMethodTag][NotificationID] -> model.Notification NotificationIDToTag map[uint64]string // [NotificationID] -> NotificationTag )
通知方式
var ( ServerList map[uint64]*model.Server // [ServerID] -> model.Server SecretToID map[string]uint64 // [ServerSecret] -> ServerID ServerTagToIDList map[string][]uint64 // [ServerTag] -> ServerID ServerLock sync.RWMutex SortedServerList []*model.Server // 用于存储服务器列表的 slice,按照服务器 ID 排序 SortedServerLock sync.RWMutex )
var Localizer *i18n.Localizer
var Version = "v0.13.30" // !!记得修改 README 中的 badge 版本!!
Functions ¶
func AddNotificationToList ¶
func AddNotificationToList(n *model.Notification)
AddNotificationToList 添加通知方式到map中
func CronTrigger ¶
func GetStatusCode ¶
func IPDesensitize ¶
IPDesensitize 根据设置选择是否对IP进行打码处理 返回处理后的IP(关闭打码则返回原IP)
func InitCronTask ¶
func InitCronTask()
func InitLocalizer ¶
func InitLocalizer()
func InitNotification ¶
func InitNotification()
InitNotification 初始化 Tag <-> ID <-> Notification 的映射
func ManualTrigger ¶
func NewServiceSentinel ¶
NewServiceSentinel 创建服务监控器
func OnDeleteAlert ¶
func OnDeleteAlert(id uint64)
func OnRefreshOrAddAlert ¶
func OnRefreshOrAddNotification ¶
func OnRefreshOrAddNotification(n *model.Notification)
OnRefreshOrAddNotification 刷新通知方式相关参数
func RecordTransferHourlyUsage ¶
func RecordTransferHourlyUsage()
RecordTransferHourlyUsage 对流量记录进行打点
func SendNotification ¶
SendNotification 向指定的通知方式组的所有通知方式发送通知
func SetDefaultNotificationTagInDB ¶
func SetDefaultNotificationTagInDB(n *model.Notification)
SetDefaultNotificationTagInDB 设置默认通知方式的 Tag
func StatusCodeToString ¶
func UpdateNotificationInList ¶
func UpdateNotificationInList(n *model.Notification)
UpdateNotificationInList 在 map 中更新通知方式
Types ¶
type CommonResponse ¶
CommonResponse 常规返回结构 包含状态码 和 状态信息
type CommonServerInfo ¶
type NotificationHistory ¶
type ReportData ¶
type ReportData struct { Data *pb.TaskResult Reporter uint64 }
type ServerAPIService ¶
type ServerAPIService struct{}
func (*ServerAPIService) GetAllList ¶
func (s *ServerAPIService) GetAllList() *ServerInfoResponse
GetAllList 获取所有服务器信息
func (*ServerAPIService) GetAllStatus ¶
func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse
GetAllStatus 获取所有服务器状态信息
func (*ServerAPIService) GetListByTag ¶
func (s *ServerAPIService) GetListByTag(tag string) *ServerInfoResponse
GetListByTag 获取传入分组的所有服务器信息
func (*ServerAPIService) GetStatusByIDList ¶
func (s *ServerAPIService) GetStatusByIDList(idList []uint64) *ServerStatusResponse
GetStatusByIDList 获取传入IDList的服务器状态信息
func (*ServerAPIService) GetStatusByTag ¶
func (s *ServerAPIService) GetStatusByTag(tag string) *ServerStatusResponse
GetStatusByTag 获取传入分组的所有服务器状态信息
type ServerInfoResponse ¶
type ServerInfoResponse struct { CommonResponse Result []*CommonServerInfo `json:"result"` }
ServerInfoResponse 服务器信息返回结构 包含常规返回结构 和 服务器信息子结构
type ServerStatusResponse ¶
type ServerStatusResponse struct { CommonResponse Result []*StatusResponse `json:"result"` }
ServerStatusResponse 服务器状态返回结构 包含常规返回结构 和 服务器状态子结构
type ServiceSentinel ¶
type ServiceSentinel struct {
// contains filtered or unexported fields
}
使用缓存 channel,处理上报的 Service 请求结果,然后判断是否需要报警 需要记录上一次的状态信息
加锁顺序:serviceResponseDataStoreLock > monthlyStatusLock > monitorsLock
func (*ServiceSentinel) Dispatch ¶
func (ss *ServiceSentinel) Dispatch(r ReportData)
Dispatch 将传入的 ReportData 传给 服务状态汇报管道
func (*ServiceSentinel) LoadStats ¶
func (ss *ServiceSentinel) LoadStats() map[uint64]*model.ServiceItemResponse
func (*ServiceSentinel) Monitors ¶
func (ss *ServiceSentinel) Monitors() []*model.Monitor
func (*ServiceSentinel) OnMonitorDelete ¶
func (ss *ServiceSentinel) OnMonitorDelete(id uint64)
func (*ServiceSentinel) OnMonitorUpdate ¶
func (ss *ServiceSentinel) OnMonitorUpdate(m model.Monitor) error
type StatusResponse ¶
type StatusResponse struct { CommonServerInfo Host *model.Host `json:"host"` Status *model.HostState `json:"status"` }
StatusResponse 服务器状态子结构 包含服务器信息与状态信息