singleton

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 20 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{}
)
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 排序
	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 Version = "v0.13.30" // !!记得修改 README 中的 badge 版本!!

Functions

func AddNotificationToList

func AddNotificationToList(n *model.Notification)

AddNotificationToList 添加通知方式到map中

func AlertSentinelStart

func AlertSentinelStart()

AlertSentinelStart 报警器启动

func CleanMonitorHistory

func CleanMonitorHistory()

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

func CronTrigger

func CronTrigger(cr model.Cron) func()

func GetStatusCode

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

func IPDesensitize

func IPDesensitize(ip string) string

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

func Init

func Init()

Init 初始化singleton

func InitAPI

func InitAPI()

func InitConfigFromPath

func InitConfigFromPath(path string)

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

func InitCronTask

func InitCronTask()

func InitDBFromPath

func InitDBFromPath(path string)

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

func InitLocalizer

func InitLocalizer()

func InitNotification

func InitNotification()

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

func InitServer

func InitServer()

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

func LoadAPI

func LoadAPI()

func LoadCronTasks

func LoadCronTasks()

LoadCronTasks 加载计划任务

func LoadNotifications

func LoadNotifications()

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

func LoadServers

func LoadServers()

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

func LoadSingleton

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

func RecordTransferHourlyUsage()

RecordTransferHourlyUsage 对流量记录进行打点

func SendNotification

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

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

func SetDefaultNotificationTagInDB

func SetDefaultNotificationTagInDB(n *model.Notification)

SetDefaultNotificationTagInDB 设置默认通知方式的 Tag

func StatusCodeToString

func StatusCodeToString(statusCode int) string

func UpdateNotificationInList

func UpdateNotificationInList(n *model.Notification)

UpdateNotificationInList 在 map 中更新通知方式

Types

type CommonResponse

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

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

type CommonServerInfo

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 NotificationHistory

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

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

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

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