singleton

package
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusNoData
	StatusGood
	StatusLowAvailability
	StatusDown
)

Variables

View Source
var (
	AlertsLock sync.RWMutex
	Alerts     []*model.AlertRule

	AlertsCycleTransferStatsStore map[uint64]*model.CycleTransferStats // [alert_id] -> 对应报警规则的周期流量统计
)

报警规则

View Source
var (
	Cron     *cron.Cron
	Crons    map[uint64]*model.Cron // [CronID] -> *model.Cron
	CronLock sync.RWMutex

	CronList []*model.Cron
)
View Source
var (
	DDNSCache     map[uint64]*model.DDNSProfile
	DDNSCacheLock sync.RWMutex
	DDNSList      []*model.DDNSProfile
)
View Source
var (
	NATCache       = make(map[string]*model.NAT)
	NATCacheRwLock sync.RWMutex

	NATIDToDomain = make(map[uint64]string)
	NATList       []*model.NAT
)
View Source
var (
	NotificationList       map[uint64]map[uint64]*model.Notification // [NotificationGroupID][NotificationID] -> model.Notification
	NotificationIDToGroups map[uint64]map[uint64]struct{}            // [NotificationID] -> NotificationGroupID

	NotificationMap        map[uint64]*model.Notification
	NotificationListSorted []*model.Notification
	NotificationGroup      map[uint64]string // [NotificationGroupID] -> [NotificationGroupName]

	NotificationsLock     sync.RWMutex
	NotificationGroupLock sync.RWMutex
)

通知方式

View Source
var (
	ServerList     map[uint64]*model.Server // [ServerID] -> model.Server
	ServerUUIDToID map[string]uint64        // [ServerUUID] -> ServerID
	ServerLock     sync.RWMutex

	SortedServerList         []*model.Server // 用于存储服务器列表的 slice,按照服务器 ID 排序
	SortedServerListForGuest []*model.Server
	SortedServerLock         sync.RWMutex
)
View Source
var (
	Conf  *model.Config
	Cache *cache.Cache
	DB    *gorm.DB
	Loc   *time.Location
)
View Source
var Localizer *i18n.Localizer
View Source
var NotificationMuteLabel _NotificationMuteLabel
View Source
var Version = "debug"

Functions

func AddNotificationGroupToList

func AddNotificationGroupToList(ng *model.NotificationGroup, ngn []uint64)

AddNotificationGroupToList 添加通知方式组到map中

func AddNotificationToList

func AddNotificationToList(n *model.Notification)

AddNotificationToList 添加通知方式到map中

func AlertSentinelStart

func AlertSentinelStart()

AlertSentinelStart 报警器启动

func CleanServiceHistory

func CleanServiceHistory()

CleanServiceHistory 清理无效或过时的 监控记录 和 流量记录

func CronTrigger

func CronTrigger(cr *model.Cron, triggerServer ...uint64) func()

func GetDDNSProvidersFromProfiles

func GetDDNSProvidersFromProfiles(profileId []uint64, ip *ddns2.IP) ([]*ddns2.Provider, error)

func GetNATConfigByDomain

func GetNATConfigByDomain(domain string) *model.NAT

func GetStatusCode

func GetStatusCode[T float32 | uint64](percent T) int

func IPDesensitize

func IPDesensitize(ip string) string

IPDesensitize 根据设置选择是否对IP进行打码处理 返回处理后的IP(关闭打码则返回原IP)

func InitConfigFromPath

func InitConfigFromPath(path string)

InitConfigFromPath 从给出的文件路径中加载配置

func InitCronTask

func InitCronTask()

func InitDBFromPath

func InitDBFromPath(path string)

InitDBFromPath 从给出的文件路径中加载数据库

func InitNotification

func InitNotification()

InitNotification 初始化 GroupID <-> ID <-> Notification 的映射

func InitServer

func InitServer()

func InitTimezoneAndCache

func InitTimezoneAndCache()

func LoadSingleton

func LoadSingleton()

LoadSingleton 加载子服务并执行

func ManualTrigger

func ManualTrigger(c *model.Cron)

func NewServiceSentinel

func NewServiceSentinel(serviceSentinelDispatchBus chan<- model.Service)

NewServiceSentinel 创建服务监控器

func OnDDNSDelete

func OnDDNSDelete(id []uint64)

func OnDDNSUpdate

func OnDDNSUpdate(p *model.DDNSProfile)

func OnDeleteAlert

func OnDeleteAlert(id []uint64)

func OnDeleteCron

func OnDeleteCron(id []uint64)

func OnDeleteNotification

func OnDeleteNotification(id []uint64)

OnDeleteNotification 在map和表中删除通知方式

func OnDeleteNotificationGroup

func OnDeleteNotificationGroup(gids []uint64)

UpdateNotificationGroupInList 删除通知方式组

func OnNATDelete

func OnNATDelete(id []uint64)

func OnNATUpdate

func OnNATUpdate(n *model.NAT)

func OnNameserverUpdate

func OnNameserverUpdate()

func OnRefreshOrAddAlert

func OnRefreshOrAddAlert(alert *model.AlertRule)

func OnRefreshOrAddCron

func OnRefreshOrAddCron(c *model.Cron)

func OnRefreshOrAddNotification

func OnRefreshOrAddNotification(n *model.Notification)

OnRefreshOrAddNotification 刷新通知方式相关参数

func OnRefreshOrAddNotificationGroup

func OnRefreshOrAddNotificationGroup(ng *model.NotificationGroup, ngn []uint64)

OnRefreshOrAddNotificationGroup 刷新通知方式组相关参数

func OnServerDelete

func OnServerDelete(sid []uint64)

func OnUpdateLang

func OnUpdateLang(lang string) error

func ReSortServer

func ReSortServer()

ReSortServer 根据服务器ID 对服务器列表进行排序(ID越大越靠前)

func RecordTransferHourlyUsage

func RecordTransferHourlyUsage()

RecordTransferHourlyUsage 对流量记录进行打点

func SendNotification

func SendNotification(notificationGroupID uint64, desc string, muteLabel *string, ext ...*model.Server)

SendNotification 向指定的通知方式组的所有通知方式发送通知

func SendTriggerTasks

func SendTriggerTasks(taskIDs []uint64, triggerServer uint64)

func StatusCodeToString

func StatusCodeToString(statusCode int) string

func UnMuteNotification

func UnMuteNotification(notificationGroupID uint64, muteLabel *string)

func UpdateCronList

func UpdateCronList()

func UpdateDDNSList

func UpdateDDNSList()

func UpdateNATList

func UpdateNATList()

func UpdateNotificationGroupInList

func UpdateNotificationGroupInList(ng *model.NotificationGroup, ngn []uint64)

UpdateNotificationGroupInList 在 map 中更新通知方式组

func UpdateNotificationInList

func UpdateNotificationInList(n *model.Notification)

UpdateNotificationInList 在 map 中更新通知方式

func UpdateNotificationList

func UpdateNotificationList()

Types

type NotificationHistory

type NotificationHistory struct {
	Duration time.Duration
	Until    time.Time
}

type ReportData

type ReportData struct {
	Data     *pb.TaskResult
	Reporter uint64
}

type ServiceSentinel

type ServiceSentinel struct {
	ServicesLock sync.RWMutex
	Services     map[uint64]*model.Service
	// contains filtered or unexported fields
}

使用缓存 channel,处理上报的 Service 请求结果,然后判断是否需要报警 需要记录上一次的状态信息

加锁顺序:serviceResponseDataStoreLock > monthlyStatusLock > servicesLock

var ServiceSentinelShared *ServiceSentinel

func (*ServiceSentinel) Dispatch

func (ss *ServiceSentinel) Dispatch(r ReportData)

Dispatch 将传入的 ReportData 传给 服务状态汇报管道

func (*ServiceSentinel) GetServiceList

func (ss *ServiceSentinel) GetServiceList() []*model.Service

func (*ServiceSentinel) LoadStats

func (ss *ServiceSentinel) LoadStats() map[uint64]*model.ServiceResponseItem

func (*ServiceSentinel) OnServiceDelete

func (ss *ServiceSentinel) OnServiceDelete(ids []uint64)

func (*ServiceSentinel) OnServiceUpdate

func (ss *ServiceSentinel) OnServiceUpdate(m model.Service) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL