cache

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: Apache-2.0 Imports: 22 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewEndpoints *list.SafeListLimited

Functions

func GetAllCounter

func GetAllCounter(tags []*TagPair) []string

GetAllCounter returns all possible tags combination. But not all of them will be in the CounterMaps.

func IndexList

func IndexList() []*model.Instance

func InitDB

func InitDB(cfg CacheSection)

func OverMaxLimit

func OverMaxLimit(tagMap map[string][]string, limit int) bool

OverMaxLimit check whether it can over limit or not.

func Persist

func Persist(mode string) error

func Rebuild

func Rebuild(persistenceDir string, concurrency int)

func RebuildFromDisk

func RebuildFromDisk(indexFileDir string, concurrency int) error

func ReportEndpoint

func ReportEndpoint()

func StartCleaner

func StartCleaner(interval int, cacheDuration int)

func StartPersist

func StartPersist(interval int)

func TagPairToMap

func TagPairToMap(tagPairs []*TagPair) map[string][]string

func WriteIndexToFile

func WriteIndexToFile(indexDir, endpoint string) error

Types

type CacheSection

type CacheSection struct {
	CacheDuration   int    `yaml:"cacheDuration"`
	CleanInterval   int    `yaml:"cleanInterval"`
	PersistInterval int    `yaml:"persistInterval"`
	PersistDir      string `yaml:"persistDir"`
	RebuildWorker   int    `yaml:"rebuildWorker"`
	MaxQueryCount   int    `yaml:"maxQueryCount"`
	ReportEndpoint  bool   `yaml:"reportEndpoint"`
}
var Config CacheSection

type CounterTsMap

type CounterTsMap struct {
	sync.RWMutex
	M map[string]int64 `json:"counters"` // map[counter]ts
}

Counter: sorted tags

func NewCounterTsMap

func NewCounterTsMap() *CounterTsMap

func (*CounterTsMap) Clean

func (c *CounterTsMap) Clean(now, timeDuration int64, endpoint, metric string)

func (*CounterTsMap) GetCounters

func (c *CounterTsMap) GetCounters() map[string]int64

func (*CounterTsMap) Len

func (c *CounterTsMap) Len() int

func (*CounterTsMap) Set

func (c *CounterTsMap) Set(counter string, ts int64)

type EndpointIndexMap

type EndpointIndexMap struct {
	sync.RWMutex
	M map[string]*MetricIndexMap `json:"endpoint_index"` //map[endpoint]metricMap{map[metric]Index}
}
var IndexDB *EndpointIndexMap

func (*EndpointIndexMap) Clean

func (e *EndpointIndexMap) Clean(timeDuration int64)

func (*EndpointIndexMap) DelByEndpoint added in v1.4.0

func (e *EndpointIndexMap) DelByEndpoint(endpoint string)

func (*EndpointIndexMap) GetEndpoints

func (e *EndpointIndexMap) GetEndpoints() []string

func (*EndpointIndexMap) GetIndexByClude

func (e *EndpointIndexMap) GetIndexByClude(endpoint, metric string, include, exclude []*TagPair) ([]string, error)

func (*EndpointIndexMap) GetMetricIndex

func (e *EndpointIndexMap) GetMetricIndex(endpoint, metric string) (*MetricIndex, bool)

func (*EndpointIndexMap) GetMetricIndexMap

func (e *EndpointIndexMap) GetMetricIndexMap(endpoint string) (*MetricIndexMap, bool)

func (*EndpointIndexMap) GetMetricsBy

func (e *EndpointIndexMap) GetMetricsBy(endpoint string) []string

func (*EndpointIndexMap) Push

func (e *EndpointIndexMap) Push(item dataobj.IndexModel, now int64)

Push 索引数据

func (*EndpointIndexMap) SetMetricIndexMap

func (e *EndpointIndexMap) SetMetricIndexMap(endpoint string, metricIndex *MetricIndexMap)

type MetricIndex

type MetricIndex struct {
	sync.RWMutex
	Metric     string        `json:"metric"`
	Step       int           `json:"step"`
	DsType     string        `json:"dstype"`
	TagkvMap   *TagkvIndex   `json:"tags"`
	CounterMap *CounterTsMap `json:"counters"`
	Ts         int64         `json:"ts"`
}

func NewMetricIndex

func NewMetricIndex(item dataobj.IndexModel, counter string, now int64) *MetricIndex

func (*MetricIndex) Set

func (m *MetricIndex) Set(item dataobj.IndexModel, counter string, now int64)

type MetricIndexMap

type MetricIndexMap struct {
	sync.RWMutex
	Reported bool // 用于判断 endpoint 是否已成功上报给 monapi
	Data     map[string]*MetricIndex
}

func ReadIndexFromFile

func ReadIndexFromFile(indexDir, endpoint string) (*MetricIndexMap, error)

func (*MetricIndexMap) Clean

func (m *MetricIndexMap) Clean(now, timeDuration int64, endpoint string)

func (*MetricIndexMap) DelMetric

func (m *MetricIndexMap) DelMetric(metric string)

func (*MetricIndexMap) GetMetricIndex

func (m *MetricIndexMap) GetMetricIndex(metric string) (*MetricIndex, bool)

func (*MetricIndexMap) GetMetrics

func (m *MetricIndexMap) GetMetrics() []string

func (*MetricIndexMap) IsReported

func (m *MetricIndexMap) IsReported() bool

func (*MetricIndexMap) Len

func (m *MetricIndexMap) Len() int

func (*MetricIndexMap) SetMetricIndex

func (m *MetricIndexMap) SetMetricIndex(metric string, metricIndex *MetricIndex)

func (*MetricIndexMap) SetReported

func (m *MetricIndexMap) SetReported()

type TagPair

type TagPair struct {
	Key    string   `json:"tagk"` // json 和变量不一致为了兼容前端
	Values []string `json:"tagv"`
}

func GetSortTags

func GetSortTags(tagMap map[string][]string) []*TagPair

type TagPairs

type TagPairs []*TagPair

func (TagPairs) Len

func (t TagPairs) Len() int

func (TagPairs) Less

func (t TagPairs) Less(i, j int) bool

func (TagPairs) Swap

func (t TagPairs) Swap(i, j int)

type TagkvIndex

type TagkvIndex struct {
	sync.RWMutex
	Tagkv map[string]map[string]int64 `json:"tagkv"` // map[tagk]map[tagv]ts
}

TagKeys

func NewTagkvIndex

func NewTagkvIndex() *TagkvIndex

func (*TagkvIndex) Clean

func (t *TagkvIndex) Clean(now, timeDuration int64)

func (*TagkvIndex) DelTag

func (t *TagkvIndex) DelTag(tagk, tagv string)

func (*TagkvIndex) GetTagkv

func (t *TagkvIndex) GetTagkv() []*TagPair

func (*TagkvIndex) GetTagkvMap

func (t *TagkvIndex) GetTagkvMap() map[string][]string

func (*TagkvIndex) Len

func (t *TagkvIndex) Len() int

func (*TagkvIndex) Set

func (t *TagkvIndex) Set(tagk, tagv string, now int64)

Jump to

Keyboard shortcuts

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