singleton

package
v1.9.11 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: Apache-2.0 Imports: 30 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 (
	OnlineUserMap     = make(map[string]*model.OnlineUser)
	OnlineUserMapLock sync.Mutex
)
View Source
var (
	Cache             *cache.Cache
	DB                *gorm.DB
	Loc               *time.Location
	FrontendTemplates []model.FrontendTemplate
	DashboardBootTime = uint64(time.Now().Unix())

	ServerShared          *ServerClass
	ServiceSentinelShared *ServiceSentinel
	DDNSShared            *DDNSClass
	NotificationShared    *NotificationClass
	NATShared             *NATClass
	CronShared            *CronClass
)
View Source
var (
	UserInfoMap         map[uint64]model.UserInfo
	AgentSecretToUserId map[string]uint64

	UserLock sync.RWMutex
)
View Source
var Localizer *i18n.Localizer
View Source
var NotificationMuteLabel _NotificationMuteLabel
View Source
var Version = "debug"

Functions

func AddOnlineUser added in v1.4.0

func AddOnlineUser(connId string, user *model.OnlineUser)

func AlertSentinelStart

func AlertSentinelStart()

AlertSentinelStart 报警器启动

func BlockByIPs added in v1.4.0

func BlockByIPs(ipList []string) error

func CleanServiceHistory

func CleanServiceHistory()

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

func CronTrigger

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

func GetOnlineUserCount added in v1.4.0

func GetOnlineUserCount() int

func GetOnlineUsers added in v1.4.0

func GetOnlineUsers(limit, offset int) []*model.OnlineUser

func GetStatusCode

func GetStatusCode[T constraints.Float | constraints.Integer](percent T) uint8

func IPDesensitize

func IPDesensitize(ip string) string

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

func InitConfigFromPath

func InitConfigFromPath(path string) error

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

func InitDBFromPath

func InitDBFromPath(path string)

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

func InitFrontendTemplates added in v1.1.4

func InitFrontendTemplates()

InitFrontendTemplates 从内置文件中加载FrontendTemplates

func InitTimezoneAndCache

func InitTimezoneAndCache()

func LoadSingleton

func LoadSingleton()

LoadSingleton 加载子服务并执行

func ManualTrigger

func ManualTrigger(cr *model.Cron)

func OnDeleteAlert

func OnDeleteAlert(id []uint64)

func OnNameserverUpdate

func OnNameserverUpdate()

func OnRefreshOrAddAlert

func OnRefreshOrAddAlert(alert *model.AlertRule)

func OnUpdateLang

func OnUpdateLang(lang string) error

func OnUserDelete added in v1.4.0

func OnUserDelete(id []uint64, errorFunc func(string, ...any) error) error

func OnUserUpdate added in v1.4.0

func OnUserUpdate(u *model.User)

func RecordTransferHourlyUsage

func RecordTransferHourlyUsage()

RecordTransferHourlyUsage 对流量记录进行打点

func RemoveOnlineUser added in v1.4.0

func RemoveOnlineUser(connId string)

func StatusCodeToString

func StatusCodeToString(statusCode uint8) string

Types

type ConfigClass added in v1.9.4

type ConfigClass struct {
	*model.Config

	IgnoredIPNotificationServerIDs map[uint64]bool `json:"ignored_ip_notification_server_ids,omitempty"`
	Oauth2Providers                []string        `json:"oauth2_providers,omitempty"`
}
var Conf *ConfigClass

func (*ConfigClass) Save added in v1.9.4

func (c *ConfigClass) Save() error

type CronClass added in v1.8.0

type CronClass struct {
	*cron.Cron
	// contains filtered or unexported fields
}

func NewCronClass added in v1.8.0

func NewCronClass() *CronClass

func (*CronClass) CheckPermission added in v1.8.0

func (c *CronClass) CheckPermission(ctx *gin.Context, idList iter.Seq[K]) bool

func (*CronClass) Delete added in v1.8.0

func (c *CronClass) Delete(idList []uint64)

func (*CronClass) Get added in v1.8.0

func (c *CronClass) Get(id K) (s V, ok bool)

func (*CronClass) GetList added in v1.8.0

func (c *CronClass) GetList() map[K]V

func (*CronClass) GetSortedList added in v1.8.0

func (c *CronClass) GetSortedList() []V

func (*CronClass) Range added in v1.8.0

func (c *CronClass) Range(fn func(k K, v V) bool)

func (*CronClass) SendTriggerTasks added in v1.8.0

func (c *CronClass) SendTriggerTasks(taskIDs []uint64, triggerServer uint64)

func (*CronClass) Update added in v1.8.0

func (c *CronClass) Update(cr *model.Cron)

type DDNSClass added in v1.8.0

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

func NewDDNSClass added in v1.8.0

func NewDDNSClass() *DDNSClass

func (*DDNSClass) CheckPermission added in v1.8.0

func (c *DDNSClass) CheckPermission(ctx *gin.Context, idList iter.Seq[K]) bool

func (*DDNSClass) Delete added in v1.8.0

func (c *DDNSClass) Delete(idList []uint64)

func (*DDNSClass) Get added in v1.8.0

func (c *DDNSClass) Get(id K) (s V, ok bool)

func (*DDNSClass) GetDDNSProvidersFromProfiles added in v1.8.0

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

func (*DDNSClass) GetList added in v1.8.0

func (c *DDNSClass) GetList() map[K]V

func (*DDNSClass) GetSortedList added in v1.8.0

func (c *DDNSClass) GetSortedList() []V

func (*DDNSClass) Range added in v1.8.0

func (c *DDNSClass) Range(fn func(k K, v V) bool)

func (*DDNSClass) Update added in v1.8.0

func (c *DDNSClass) Update(p *model.DDNSProfile)

type NATClass added in v1.8.0

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

func NewNATClass added in v1.8.0

func NewNATClass() *NATClass

func (*NATClass) CheckPermission added in v1.8.0

func (c *NATClass) CheckPermission(ctx *gin.Context, idList iter.Seq[K]) bool

func (*NATClass) Delete added in v1.8.0

func (c *NATClass) Delete(idList []uint64)

func (*NATClass) Get added in v1.8.0

func (c *NATClass) Get(id K) (s V, ok bool)

func (*NATClass) GetDomain added in v1.8.0

func (c *NATClass) GetDomain(id uint64) string

func (*NATClass) GetList added in v1.8.0

func (c *NATClass) GetList() map[K]V

func (*NATClass) GetNATConfigByDomain added in v1.8.0

func (c *NATClass) GetNATConfigByDomain(domain string) *model.NAT

func (*NATClass) GetSortedList added in v1.8.0

func (c *NATClass) GetSortedList() []V

func (*NATClass) Range added in v1.8.0

func (c *NATClass) Range(fn func(k K, v V) bool)

func (*NATClass) Update added in v1.8.0

func (c *NATClass) Update(n *model.NAT)

type NotificationClass added in v1.8.0

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

func NewNotificationClass added in v1.8.0

func NewNotificationClass() *NotificationClass

func (*NotificationClass) CheckPermission added in v1.8.0

func (c *NotificationClass) CheckPermission(ctx *gin.Context, idList iter.Seq[K]) bool

func (*NotificationClass) Delete added in v1.8.0

func (c *NotificationClass) Delete(idList []uint64)

func (*NotificationClass) DeleteGroup added in v1.8.0

func (c *NotificationClass) DeleteGroup(gids []uint64)

func (*NotificationClass) Get added in v1.8.0

func (c *NotificationClass) Get(id K) (s V, ok bool)

func (*NotificationClass) GetGroupName added in v1.8.0

func (c *NotificationClass) GetGroupName(gid uint64) string

func (*NotificationClass) GetList added in v1.8.0

func (c *NotificationClass) GetList() map[K]V

func (*NotificationClass) GetSortedList added in v1.8.0

func (c *NotificationClass) GetSortedList() []V

func (*NotificationClass) Range added in v1.8.0

func (c *NotificationClass) Range(fn func(k K, v V) bool)

func (*NotificationClass) SendNotification added in v1.8.0

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

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

func (*NotificationClass) UnMuteNotification added in v1.8.0

func (c *NotificationClass) UnMuteNotification(notificationGroupID uint64, muteLabel string)

func (*NotificationClass) Update added in v1.8.0

func (c *NotificationClass) Update(n *model.Notification)

func (*NotificationClass) UpdateGroup added in v1.8.0

func (c *NotificationClass) UpdateGroup(ng *model.NotificationGroup, ngn []uint64)

type NotificationHistory

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

type ReportData

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

type ServerClass added in v1.8.0

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

func NewServerClass added in v1.8.0

func NewServerClass() *ServerClass

func (*ServerClass) CheckPermission added in v1.8.0

func (c *ServerClass) CheckPermission(ctx *gin.Context, idList iter.Seq[K]) bool

func (*ServerClass) Delete added in v1.8.0

func (c *ServerClass) Delete(idList []uint64)

func (*ServerClass) Get added in v1.8.0

func (c *ServerClass) Get(id K) (s V, ok bool)

func (*ServerClass) GetList added in v1.8.0

func (c *ServerClass) GetList() map[K]V

func (*ServerClass) GetSortedList added in v1.8.0

func (c *ServerClass) GetSortedList() []V

func (*ServerClass) GetSortedListForGuest added in v1.8.0

func (c *ServerClass) GetSortedListForGuest() []*model.Server

func (*ServerClass) Range added in v1.8.0

func (c *ServerClass) Range(fn func(k K, v V) bool)

func (*ServerClass) UUIDToID added in v1.8.0

func (c *ServerClass) UUIDToID(uuid string) (id uint64, ok bool)

func (*ServerClass) Update added in v1.8.0

func (c *ServerClass) Update(s *model.Server, uuid string)

type ServiceSentinel

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

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

加锁顺序:serviceResponseDataStoreLock > monthlyStatusLock > servicesLock

func NewServiceSentinel

func NewServiceSentinel(serviceSentinelDispatchBus chan<- *model.Service, sc *ServerClass, nc *NotificationClass, crc *CronClass) (*ServiceSentinel, error)

NewServiceSentinel 创建服务监控器

func (*ServiceSentinel) CheckPermission added in v1.8.0

func (ss *ServiceSentinel) CheckPermission(c *gin.Context, idList iter.Seq[uint64]) bool

func (*ServiceSentinel) CopyStats added in v1.0.22

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

func (*ServiceSentinel) Delete added in v1.8.0

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

func (*ServiceSentinel) Dispatch

func (ss *ServiceSentinel) Dispatch(r ReportData)

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

func (*ServiceSentinel) Get added in v1.8.0

func (ss *ServiceSentinel) Get(id uint64) (s *model.Service, ok bool)

func (*ServiceSentinel) GetList added in v1.8.0

func (ss *ServiceSentinel) GetList() map[uint64]*model.Service

func (*ServiceSentinel) GetSortedList added in v1.8.0

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

func (*ServiceSentinel) LoadStats

func (ss *ServiceSentinel) LoadStats() map[uint64]*serviceResponseItem

func (*ServiceSentinel) Update added in v1.8.0

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

func (*ServiceSentinel) UpdateServiceList added in v1.0.22

func (ss *ServiceSentinel) UpdateServiceList()

Jump to

Keyboard shortcuts

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