cache

package
v4.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const CHECK_INTERVAL = 9
View Source
const DetectorReplicas = 500
View Source
const JudgesReplicas = 500
View Source
const ProbersReplicas = 500

Variables

View Source
var ActiveJudgeNode = NewNodeMap()
View Source
var (
	AggrCalcMap = &SafeAggrCalcMap{
		M:         make(map[string]map[string][]*dataobj.RawMetricAggrCalc),
		MetricMap: make(map[int64]string),
	}
)
View Source
var ApiDetectorHashRing map[string]*ConsistentHashRing
View Source
var CollectRuleCache *collectRuleCache
View Source
var CommonModule string
View Source
var (
	DefaultCache = &Cache{
		interval: 10,
		config: configCache{
			authConfig: &models.DefaultAuthConfig,
		},
	}
)
View Source
var HistoryBigMap = make(map[string]*JudgeItemMap)

这是个线程不安全的大Map,需要提前初始化好

View Source
var (
	LastEvents = &SafeEventMap{M: make(map[string]*dataobj.Event)}
)
View Source
var SnmpDetectorHashRing map[string]*ConsistentHashRing
View Source
var (
	StraMap = &SafeStraMap{M: make(map[string]map[string][]*models.Stra)}
)

Functions

func AuthConfig

func AuthConfig() *models.AuthConfig

func GetLeafNidsForMon added in v4.0.4

func GetLeafNidsForMon(nid int64, exclNid []int64) ([]int64, error)

func GetRelatedNidsForMon added in v4.0.4

func GetRelatedNidsForMon(nid int64, exclNid []int64) ([]int64, error)

func Init

func Init(regions []string)

func InitApiDetectorHashRing

func InitApiDetectorHashRing(regions []string)

func InitHistoryBigMap

func InitHistoryBigMap()

func InitJudgeHashRing

func InitJudgeHashRing()

func InitSnmpDetectorHashRing

func InitSnmpDetectorHashRing(regions []string)

func LoadFile

func LoadFile() (map[string][]*dataobj.Metric, error)

func LoadMetrics

func LoadMetrics()

func NewCollectRuleCache

func NewCollectRuleCache(regions []string) *collectRuleCache

func RebuildConsistentHashRing

func RebuildConsistentHashRing(hashRing *ConsistentHashRing, nodes []string, replicas int)

func Start

func Start()

func Stop

func Stop()

func SyncHashIdEventCur added in v4.0.4

func SyncHashIdEventCur()

Types

type AggrCalcCacheMap

type AggrCalcCacheMap struct {
	sync.RWMutex
	Data []*models.AggrCalc
}
var AggrCalcStraCache *AggrCalcCacheMap

func NewAggrCalcStraCache

func NewAggrCalcStraCache() *AggrCalcCacheMap

func (*AggrCalcCacheMap) Get

func (a *AggrCalcCacheMap) Get() []*models.AggrCalc

func (*AggrCalcCacheMap) Set

func (a *AggrCalcCacheMap) Set(stras []*models.AggrCalc)

type AlarmStraCacheMap

type AlarmStraCacheMap struct {
	sync.RWMutex
	Data map[int64]*models.Stra
}
var AlarmStraCache *AlarmStraCacheMap

func NewAlarmStraCache

func NewAlarmStraCache() *AlarmStraCacheMap

func (*AlarmStraCacheMap) GetById

func (this *AlarmStraCacheMap) GetById(id int64) (*models.Stra, bool)

func (*AlarmStraCacheMap) SetAll

func (this *AlarmStraCacheMap) SetAll(m map[int64]*models.Stra)

type ApiCollectCacheMap

type ApiCollectCacheMap struct {
	sync.RWMutex
	Data map[string][]*models.ApiCollect
}
var ApiCollectCache *ApiCollectCacheMap

func NewApiCollectCache

func NewApiCollectCache() *ApiCollectCacheMap

func (*ApiCollectCacheMap) GetBy

func (c *ApiCollectCacheMap) GetBy(node string) []*models.ApiCollect

func (*ApiCollectCacheMap) Set

func (c *ApiCollectCacheMap) Set(node string, collects []*models.ApiCollect)

func (*ApiCollectCacheMap) SetAll

func (c *ApiCollectCacheMap) SetAll(data map[string][]*models.ApiCollect)

type Cache

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

func NewCache

func NewCache(interval int) *Cache

func (*Cache) Start

func (p *Cache) Start()

func (*Cache) Stop

func (p *Cache) Stop()

type CollectCacheMap

type CollectCacheMap struct {
	sync.RWMutex
	Data map[string]*models.Collect
}
var CollectCache *CollectCacheMap

func NewCollectCache

func NewCollectCache() *CollectCacheMap

func (*CollectCacheMap) GetBy

func (c *CollectCacheMap) GetBy(endpoint string) *models.Collect

func (*CollectCacheMap) Set

func (c *CollectCacheMap) Set(endpoint string, collect *models.Collect)

func (*CollectCacheMap) SetAll

func (c *CollectCacheMap) SetAll(strasMap map[string]*models.Collect)

type ConsistentHashRing

type ConsistentHashRing struct {
	sync.RWMutex
	// contains filtered or unexported fields
}
var JudgeHashRing *ConsistentHashRing

func NewConsistentHashRing

func NewConsistentHashRing(replicas int32, nodes []string) *ConsistentHashRing

func (*ConsistentHashRing) GetNode

func (this *ConsistentHashRing) GetNode(pk string) (string, error)

func (*ConsistentHashRing) GetRing

func (this *ConsistentHashRing) GetRing() *consistent.Consistent

func (*ConsistentHashRing) Set

type HashIdEventCurMap added in v4.0.4

type HashIdEventCurMap struct {
	sync.RWMutex
	Data map[uint64]*models.EventCur
}
var HashIdEventCurMapCache *HashIdEventCurMap

func NewHashIdEventCurMapCache added in v4.0.4

func NewHashIdEventCurMapCache() *HashIdEventCurMap

func (*HashIdEventCurMap) GetAll added in v4.0.4

func (t *HashIdEventCurMap) GetAll() []*models.EventCur

func (*HashIdEventCurMap) GetBy added in v4.0.4

func (t *HashIdEventCurMap) GetBy(hashid uint64) *models.EventCur

func (*HashIdEventCurMap) SetAll added in v4.0.4

func (t *HashIdEventCurMap) SetAll(objs map[uint64]*models.EventCur)

type IndexMap

type IndexMap struct {
	sync.RWMutex
	Data map[int64]map[string]Series
}
var SeriesMap *IndexMap

func NewIndexMap

func NewIndexMap() *IndexMap

func (*IndexMap) Clean

func (i *IndexMap) Clean()

func (*IndexMap) CleanLoop

func (i *IndexMap) CleanLoop()

func (*IndexMap) Get

func (i *IndexMap) Get(id int64) []Series

func (*IndexMap) Set

func (i *IndexMap) Set(id int64, hash string, s Series)

type JudgeItemMap

type JudgeItemMap struct {
	sync.RWMutex
	M map[string]*SafeLinkedList
}

func NewJudgeItemMap

func NewJudgeItemMap() *JudgeItemMap

func (*JudgeItemMap) BatchDelete

func (j *JudgeItemMap) BatchDelete(keys []string)

func (*JudgeItemMap) CleanStale

func (j *JudgeItemMap) CleanStale(before int64)

func (*JudgeItemMap) Get

func (j *JudgeItemMap) Get(key string) (*SafeLinkedList, bool)

func (*JudgeItemMap) Len

func (j *JudgeItemMap) Len() int

func (*JudgeItemMap) Set

func (j *JudgeItemMap) Set(key string, val *SafeLinkedList)

type MaskCacheMap

type MaskCacheMap struct {
	sync.RWMutex
	Data map[string][]string
}
var MaskCache *MaskCacheMap

func NewMaskCache

func NewMaskCache() *MaskCacheMap

func (*MaskCacheMap) GetByKey

func (this *MaskCacheMap) GetByKey(key string) ([]string, bool)

func (*MaskCacheMap) SetAll

func (this *MaskCacheMap) SetAll(m map[string][]string)

type ModuleMetricMap

type ModuleMetricMap struct {
	sync.RWMutex
	Data map[string]map[string]*dataobj.Metric
}
var ModuleMetric ModuleMetricMap

func (*ModuleMetricMap) Get

func (m *ModuleMetricMap) Get(module, metricName string) (*dataobj.Metric, bool)

func (*ModuleMetricMap) GetByModule

func (m *ModuleMetricMap) GetByModule(module string) map[string]*dataobj.Metric

func (*ModuleMetricMap) Set

func (m *ModuleMetricMap) Set(module string, metrics map[string]*dataobj.Metric)

type NodeIdentsMap added in v4.0.4

type NodeIdentsMap struct {
	sync.RWMutex
	Data map[int64][]*models.Resource
}
var NodeIdentsMapCache *NodeIdentsMap

func NewNodeIdentsMapCache added in v4.0.4

func NewNodeIdentsMapCache() *NodeIdentsMap

func (*NodeIdentsMap) GetBy added in v4.0.4

func (t *NodeIdentsMap) GetBy(id int64) []*models.Resource

func (*NodeIdentsMap) SetAll added in v4.0.4

func (t *NodeIdentsMap) SetAll(objs map[int64][]*models.Resource)

type NodeMap

type NodeMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewNodeMap

func NewNodeMap() NodeMap

func (*NodeMap) GetInstanceBy

func (n *NodeMap) GetInstanceBy(node string) (string, bool)

func (*NodeMap) GetNodeBy

func (n *NodeMap) GetNodeBy(instance string) (string, bool)

func (*NodeMap) GetNodes

func (n *NodeMap) GetNodes() []string

func (*NodeMap) Len

func (n *NodeMap) Len() int

func (*NodeMap) Set

func (n *NodeMap) Set(nodeMap map[string]string)

type NodeResourceMap added in v4.0.4

type NodeResourceMap struct {
	sync.RWMutex
	Data map[int64][]int64
}
var NodeResourceCache *NodeResourceMap

func NewNodeResourceCache added in v4.0.4

func NewNodeResourceCache() *NodeResourceMap

func (*NodeResourceMap) GetByNids added in v4.0.4

func (t *NodeResourceMap) GetByNids(ids []int64) []int64

func (*NodeResourceMap) GetResourceBy added in v4.0.4

func (t *NodeResourceMap) GetResourceBy(id int64) []int64

func (*NodeResourceMap) SetAll added in v4.0.4

func (t *NodeResourceMap) SetAll(objs map[int64][]int64)

type ResourceMap added in v4.0.4

type ResourceMap struct {
	sync.RWMutex
	Data map[int64]*models.Resource
}
var ResourceCache *ResourceMap

func NewResourceCache added in v4.0.4

func NewResourceCache() *ResourceMap

func (*ResourceMap) GetBy added in v4.0.4

func (t *ResourceMap) GetBy(id int64) *models.Resource

func (*ResourceMap) GetByIds added in v4.0.4

func (t *ResourceMap) GetByIds(ids []int64) []*models.Resource

func (*ResourceMap) SetAll added in v4.0.4

func (t *ResourceMap) SetAll(objs map[int64]*models.Resource)

type SafeAggrCalcMap

type SafeAggrCalcMap struct {
	sync.RWMutex
	M         map[string]map[string][]*dataobj.RawMetricAggrCalc
	MetricMap map[int64]string
}

func (*SafeAggrCalcMap) GetAll

func (s *SafeAggrCalcMap) GetAll() []*dataobj.RawMetricAggrCalc

func (*SafeAggrCalcMap) GetByKey

func (s *SafeAggrCalcMap) GetByKey(key string) []*dataobj.RawMetricAggrCalc

func (*SafeAggrCalcMap) GetMetric

func (s *SafeAggrCalcMap) GetMetric(id int64) string

func (*SafeAggrCalcMap) ReInit

func (s *SafeAggrCalcMap) ReInit(m map[string]map[string][]*dataobj.RawMetricAggrCalc)

func (*SafeAggrCalcMap) ReInitMetric

func (s *SafeAggrCalcMap) ReInitMetric(m map[int64]string)

type SafeEventMap

type SafeEventMap struct {
	sync.RWMutex
	M map[string]*dataobj.Event
}

func (*SafeEventMap) Get

func (s *SafeEventMap) Get(key string) (*dataobj.Event, bool)

func (*SafeEventMap) Set

func (s *SafeEventMap) Set(key string, event *dataobj.Event)

type SafeJudgeQueue

type SafeJudgeQueue struct {
	sync.RWMutex
	Data map[string]*list.SafeListLimited
	Ts   map[string]int64
}

func NewJudgeQueue

func NewJudgeQueue() SafeJudgeQueue

func (*SafeJudgeQueue) Clean

func (s *SafeJudgeQueue) Clean()

func (*SafeJudgeQueue) Del

func (s *SafeJudgeQueue) Del(instance string)

func (*SafeJudgeQueue) Exists

func (s *SafeJudgeQueue) Exists(instance string) bool

func (*SafeJudgeQueue) Get

func (s *SafeJudgeQueue) Get(instance string) (*list.SafeListLimited, bool)

func (*SafeJudgeQueue) GetAll

func (s *SafeJudgeQueue) GetAll() map[string]*list.SafeListLimited

func (*SafeJudgeQueue) Set

func (s *SafeJudgeQueue) Set(instance string, q *list.SafeListLimited)

func (*SafeJudgeQueue) UpdateTS

func (s *SafeJudgeQueue) UpdateTS(instance string)

type SafeLinkedList

type SafeLinkedList struct {
	sync.RWMutex
	L *list.List
}

func (*SafeLinkedList) Front

func (ll *SafeLinkedList) Front() *list.Element

func (*SafeLinkedList) HistoryData

func (ll *SafeLinkedList) HistoryData() []*dataobj.HistoryData

@param limit 至多返回这些,如果不够,有多少返回多少

func (*SafeLinkedList) Len

func (ll *SafeLinkedList) Len() int

func (*SafeLinkedList) PushFrontAndMaintain

func (ll *SafeLinkedList) PushFrontAndMaintain(v *dataobj.JudgeItem, alertDur int) bool

@return needJudge 如果是false不需要做judge,因为新上来的数据不合法

func (*SafeLinkedList) QueryDataByTS

func (ll *SafeLinkedList) QueryDataByTS(start, end int64) []*dataobj.HistoryData

type SafeStraMap

type SafeStraMap struct {
	sync.RWMutex
	M map[string]map[string][]*models.Stra
}

func (*SafeStraMap) GetAll

func (s *SafeStraMap) GetAll() []*models.Stra

func (*SafeStraMap) GetByKey

func (s *SafeStraMap) GetByKey(key string) []*models.Stra

func (*SafeStraMap) ReInit

func (s *SafeStraMap) ReInit(m map[string]map[string][]*models.Stra)

type Series

type Series struct {
	Endpoint string
	Nid      string
	Metric   string
	Tag      string
	Step     int
	Dstype   string
	TS       int64
}

type SnmpCollectCacheMap

type SnmpCollectCacheMap struct {
	sync.RWMutex
	Data map[string][]*dataobj.IPAndSnmp
}

snmp

var SnmpCollectCache *SnmpCollectCacheMap

func NewSnmpCollectCache

func NewSnmpCollectCache() *SnmpCollectCacheMap

func (*SnmpCollectCacheMap) GetBy

func (c *SnmpCollectCacheMap) GetBy(node string) []*dataobj.IPAndSnmp

func (*SnmpCollectCacheMap) Set

func (c *SnmpCollectCacheMap) Set(node string, collects []*dataobj.IPAndSnmp)

func (*SnmpCollectCacheMap) SetAll

func (c *SnmpCollectCacheMap) SetAll(data map[string][]*dataobj.IPAndSnmp)

type SnmpHWCacheMap

type SnmpHWCacheMap struct {
	sync.RWMutex
	Data map[string][]*models.NetworkHardware
}
var SnmpHWCache *SnmpHWCacheMap

func NewSnmpHWCache

func NewSnmpHWCache() *SnmpHWCacheMap

func (*SnmpHWCacheMap) GetBy

func (c *SnmpHWCacheMap) GetBy(node string) []*models.NetworkHardware

func (*SnmpHWCacheMap) Set

func (c *SnmpHWCacheMap) Set(node string, hws []*models.NetworkHardware)

func (*SnmpHWCacheMap) SetAll

func (c *SnmpHWCacheMap) SetAll(data map[string][]*models.NetworkHardware)

type StraCacheMap

type StraCacheMap struct {
	sync.RWMutex
	Data map[string][]*models.Stra
}
var StraCache *StraCacheMap

func NewStraCache

func NewStraCache() *StraCacheMap

func (*StraCacheMap) GetAll

func (s *StraCacheMap) GetAll() []*models.Stra

func (*StraCacheMap) GetByNode

func (s *StraCacheMap) GetByNode(node string) []*models.Stra

func (*StraCacheMap) Set

func (s *StraCacheMap) Set(node string, stras []*models.Stra)

func (*StraCacheMap) SetAll

func (s *StraCacheMap) SetAll(strasMap map[string][]*models.Stra)

type StrategyMap

type StrategyMap struct {
	sync.RWMutex
	Data map[int64]*models.Stra
	TS   map[int64]int64
}
var NodataStra *StrategyMap
var Strategy *StrategyMap

func NewStrategyMap

func NewStrategyMap() *StrategyMap

func (*StrategyMap) Clean

func (s *StrategyMap) Clean()

func (*StrategyMap) Get

func (s *StrategyMap) Get(id int64) (*models.Stra, bool)

func (*StrategyMap) GetAll

func (s *StrategyMap) GetAll() []*models.Stra

func (*StrategyMap) Set

func (s *StrategyMap) Set(id int64, stra *models.Stra)

type TeamMap added in v4.0.2

type TeamMap struct {
	sync.RWMutex
	Data map[int64]*models.Team
}
var TeamCache *TeamMap

func NewTeamCache added in v4.0.2

func NewTeamCache() *TeamMap

func (*TeamMap) GetBy added in v4.0.2

func (s *TeamMap) GetBy(id int64) *models.Team

func (*TeamMap) GetByIds added in v4.0.2

func (s *TeamMap) GetByIds(ids []int64) []*models.Team

func (*TeamMap) GetTeamNamesByIds added in v4.0.2

func (s *TeamMap) GetTeamNamesByIds(ids string) []string

func (*TeamMap) SetAll added in v4.0.2

func (s *TeamMap) SetAll(objs map[int64]*models.Team)

type TeamUsersMap added in v4.0.2

type TeamUsersMap struct {
	sync.RWMutex
	Data map[int64][]int64
}
var TeamUsersCache *TeamUsersMap

func NewTeamUsersCache added in v4.0.2

func NewTeamUsersCache() *TeamUsersMap

func (*TeamUsersMap) GetBy added in v4.0.2

func (s *TeamUsersMap) GetBy(id int64) []int64

func (*TeamUsersMap) GetByTeamIds added in v4.0.2

func (s *TeamUsersMap) GetByTeamIds(ids []int64) []int64

func (*TeamUsersMap) SetAll added in v4.0.2

func (s *TeamUsersMap) SetAll(data map[int64][]int64)

type TreeNodeMap added in v4.0.2

type TreeNodeMap struct {
	sync.RWMutex
	Data map[int64]*models.Node
}
var TreeNodeCache *TreeNodeMap

func NewTreeNodeCache added in v4.0.2

func NewTreeNodeCache() *TreeNodeMap

func (*TreeNodeMap) GetAll added in v4.0.4

func (t *TreeNodeMap) GetAll() []*models.Node

func (*TreeNodeMap) GetBy added in v4.0.2

func (t *TreeNodeMap) GetBy(id int64) *models.Node

func (*TreeNodeMap) GetByIds added in v4.0.2

func (t *TreeNodeMap) GetByIds(ids []int64) []*models.Node

func (*TreeNodeMap) GetLeafNidsById added in v4.0.4

func (t *TreeNodeMap) GetLeafNidsById(id int64) []int64

func (*TreeNodeMap) Len added in v4.0.4

func (t *TreeNodeMap) Len() int

func (*TreeNodeMap) SetAll added in v4.0.2

func (t *TreeNodeMap) SetAll(objs map[int64]*models.Node)

type UserMap added in v4.0.2

type UserMap struct {
	sync.RWMutex
	Data map[int64]*models.User
}
var UserCache *UserMap

func NewUserCache added in v4.0.2

func NewUserCache() *UserMap

func (*UserMap) GetBy added in v4.0.2

func (s *UserMap) GetBy(id int64) *models.User

func (*UserMap) GetByIds added in v4.0.2

func (s *UserMap) GetByIds(ids []int64) []*models.User

func (*UserMap) GetUsernamesByIds added in v4.0.2

func (s *UserMap) GetUsernamesByIds(ids string) []string

func (*UserMap) SetAll added in v4.0.2

func (s *UserMap) SetAll(users map[int64]*models.User)

Jump to

Keyboard shortcuts

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