singleton

package
v0.16.22 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 21 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 (
	ApiTokenList         = make(map[string]*model.ApiToken)
	UserIDToApiTokenList = make(map[uint64][]string)
	ApiLock              sync.RWMutex

	ServerAPI  = &ServerAPIService{}
	MonitorAPI = &MonitorAPIService{}
)
View Source
var (
	Cron     *cron.Cron
	Crons    map[uint64]*model.Cron // [CrondID] -> *model.Cron
	CronLock sync.RWMutex
)
View Source
var (
	NotificationList    map[string]map[uint64]*model.Notification // [NotificationMethodTag][NotificationID] -> model.Notification
	NotificationIDToTag map[uint64]string                         // [NotificationID] -> NotificationTag

)

通知方式

View Source
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 排序
	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 AddNotificationToList added in v0.12.15

func AddNotificationToList(n *model.Notification)

AddNotificationToList 添加通知方式到map中

func AlertSentinelStart

func AlertSentinelStart()

AlertSentinelStart 报警器启动

func CleanMonitorHistory added in v0.12.14

func CleanMonitorHistory()

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

func CronTrigger

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

func GetDDNSProviderFromString added in v0.16.5

func GetDDNSProviderFromString(provider string) (ddns2.Provider, error)

func GetStatusCode added in v0.13.0

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

func IPDesensitize added in v0.12.4

func IPDesensitize(ip string) string

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

func InitAPI added in v0.13.2

func InitAPI()

func InitConfigFromPath added in v0.12.14

func InitConfigFromPath(path string)

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

func InitCronTask added in v0.12.14

func InitCronTask()

func InitDBFromPath added in v0.12.14

func InitDBFromPath(path string)

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

func InitLocalizer added in v0.12.15

func InitLocalizer()

func InitNotification added in v0.12.15

func InitNotification()

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

func InitServer added in v0.12.14

func InitServer()

InitServer 初始化 ServerID <-> Secret 的映射

func InitTimezoneAndCache added in v0.14.2

func InitTimezoneAndCache()

func LoadAPI added in v0.13.2

func LoadAPI()

func LoadCronTasks added in v0.12.14

func LoadCronTasks()

LoadCronTasks 加载计划任务

func LoadNotifications

func LoadNotifications()

LoadNotifications 从 DB 初始化通知方式相关参数

func LoadServers added in v0.12.14

func LoadServers()

LoadServers 加载服务器列表并根据ID排序

func LoadSingleton added in v0.12.14

func LoadSingleton()

LoadSingleton 加载子服务并执行

func ManualTrigger

func ManualTrigger(c model.Cron)

func NewServiceSentinel

func NewServiceSentinel(serviceSentinelDispatchBus chan<- model.Monitor)

NewServiceSentinel 创建服务监控器

func OnDeleteAlert

func OnDeleteAlert(id uint64)

func OnDeleteNotification

func OnDeleteNotification(id uint64)

OnDeleteNotification 在map中删除通知方式

func OnRefreshOrAddAlert

func OnRefreshOrAddAlert(alert model.AlertRule)

func OnRefreshOrAddNotification

func OnRefreshOrAddNotification(n *model.Notification)

OnRefreshOrAddNotification 刷新通知方式相关参数

func ReSortServer

func ReSortServer()

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

func RecordTransferHourlyUsage added in v0.12.14

func RecordTransferHourlyUsage()

RecordTransferHourlyUsage 对流量记录进行打点

func RetryableUpdateDomain added in v0.16.5

func RetryableUpdateDomain(provider ddns2.Provider, config *ddns2.DomainConfig, maxRetries int) bool

func SendNotification

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

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

func SendTriggerTasks added in v0.14.0

func SendTriggerTasks(taskIDs []uint64, triggerServer uint64)

func SetDefaultNotificationTagInDB added in v0.12.15

func SetDefaultNotificationTagInDB(n *model.Notification)

SetDefaultNotificationTagInDB 设置默认通知方式的 Tag

func StatusCodeToString added in v0.13.0

func StatusCodeToString(statusCode int) string

func UnMuteNotification added in v0.15.7

func UnMuteNotification(notificationTag string, muteLabel *string)

func UpdateNotificationInList added in v0.12.15

func UpdateNotificationInList(n *model.Notification)

UpdateNotificationInList 在 map 中更新通知方式

func ValidateConfig added in v0.16.5

func ValidateConfig()

ValidateConfig 验证配置文件有效性

Types

type CommonResponse added in v0.13.2

type CommonResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

CommonResponse 常规返回结构 包含状态码 和 状态信息

type CommonServerInfo added in v0.13.2

type CommonServerInfo struct {
	ID         uint64 `json:"id"`
	Name       string `json:"name"`
	Tag        string `json:"tag"`
	LastActive int64  `json:"last_active"`
	IPV4       string `json:"ipv4"`
	IPV6       string `json:"ipv6"`
	ValidIP    string `json:"valid_ip"`
}

type MonitorAPIService added in v0.16.0

type MonitorAPIService struct {
}

func (*MonitorAPIService) GetMonitorHistories added in v0.16.0

func (m *MonitorAPIService) GetMonitorHistories(query map[string]any) *MonitorInfoResponse

type MonitorInfo added in v0.16.0

type MonitorInfo struct {
	MonitorID   uint64    `json:"monitor_id"`
	ServerID    uint64    `json:"server_id"`
	MonitorName string    `json:"monitor_name"`
	ServerName  string    `json:"server_name"`
	CreatedAt   []int64   `json:"created_at"`
	AvgDelay    []float32 `json:"avg_delay"`
}

type MonitorInfoResponse added in v0.16.0

type MonitorInfoResponse struct {
	CommonResponse
	Result []*MonitorInfo `json:"result"`
}

type NotificationHistory

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

type ReportData

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

type ServerAPIService added in v0.13.2

type ServerAPIService struct{}

func (*ServerAPIService) GetAllList added in v0.13.2

func (s *ServerAPIService) GetAllList() *ServerInfoResponse

GetAllList 获取所有服务器信息

func (*ServerAPIService) GetAllStatus added in v0.13.2

func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse

GetAllStatus 获取所有服务器状态信息

func (*ServerAPIService) GetListByTag added in v0.13.2

func (s *ServerAPIService) GetListByTag(tag string) *ServerInfoResponse

GetListByTag 获取传入分组的所有服务器信息

func (*ServerAPIService) GetStatusByIDList added in v0.13.2

func (s *ServerAPIService) GetStatusByIDList(idList []uint64) *ServerStatusResponse

GetStatusByIDList 获取传入IDList的服务器状态信息

func (*ServerAPIService) GetStatusByTag added in v0.13.2

func (s *ServerAPIService) GetStatusByTag(tag string) *ServerStatusResponse

GetStatusByTag 获取传入分组的所有服务器状态信息

type ServerInfoResponse added in v0.13.2

type ServerInfoResponse struct {
	CommonResponse
	Result []*CommonServerInfo `json:"result"`
}

ServerInfoResponse 服务器信息返回结构 包含常规返回结构 和 服务器信息子结构

type ServerStatusResponse added in v0.13.2

type ServerStatusResponse struct {
	CommonResponse
	Result []*StatusResponse `json:"result"`
}

ServerStatusResponse 服务器状态返回结构 包含常规返回结构 和 服务器状态子结构

type ServiceSentinel

type ServiceSentinel struct {
	// contains filtered or unexported fields
}

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

加锁顺序:serviceResponseDataStoreLock > monthlyStatusLock > monitorsLock

var ServiceSentinelShared *ServiceSentinel

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 added in v0.13.2

type StatusResponse struct {
	CommonServerInfo
	Host   *model.Host      `json:"host"`
	Status *model.HostState `json:"status"`
}

StatusResponse 服务器状态子结构 包含服务器信息与状态信息

Jump to

Keyboard shortcuts

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