metric

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Before .
	Before int = iota
	// Inside .
	Inside
	// After .
	After
)

Variables

This section is empty.

Functions

func GetCurrentMilliseconds

func GetCurrentMilliseconds(startTime time.Time) int64

GetCurrentMilliseconds 获取当前的相对毫秒值

Types

type AddBucketFunc

type AddBucketFunc func(gauge model.InstanceGauge, bucket *Bucket) int64

AddBucketFunc 回调函数,用于将统计数据入桶

type Bucket

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

Bucket 统计单元

func (*Bucket) AddMetric

func (b *Bucket) AddMetric(dimension int, value int64) int64

AddMetric 累加统计值

func (*Bucket) CalcBucketMetrics

func (b *Bucket) CalcBucketMetrics(dimensions []int, startTime int64, endTime int64, rangeType IntervalType) []int64

CalcBucketMetrics 计算时间范围内的桶的统计值,如果这个桶包括在时间范围内,那么计算,否则不计入

func (*Bucket) GetMetric

func (b *Bucket) GetMetric(dimension int) int64

GetMetric 获取统计值

func (*Bucket) SetMetric

func (b *Bucket) SetMetric(dimension int, value int64)

SetMetric 设置统计值

type BucketOperation

type BucketOperation func(bucket *Bucket) int64

BucketOperation 限流桶操作函数

type GaugeOperation

type GaugeOperation struct {
	Gauge     model.InstanceGauge
	Operation AddBucketFunc
}

GaugeOperation 封装类型,封装统计数据,以及添加统计的操作回调

type IntervalType

type IntervalType int

IntervalType timeRange的类型

const (
	// IncludeStart .
	IncludeStart IntervalType = iota
	// IncludeEnd .
	IncludeEnd
	// IncludeBoth .
	IncludeBoth
)

func (IntervalType) String

func (i IntervalType) String() string

String 将IntervalType转化为string

type ResMetricArray

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

ResMetricArray 资源统计序列

func NewResMetricArray

func NewResMetricArray(metricSize int) *ResMetricArray

NewResMetricArray 创建资源统计序列

func (*ResMetricArray) AddMetric

func (r *ResMetricArray) AddMetric(dimension int, value int64) int64

AddMetric 累加统计值

func (*ResMetricArray) GetMetric

func (r *ResMetricArray) GetMetric(dimension int) int64

GetMetric 获取统计值

func (*ResMetricArray) SetMetric

func (r *ResMetricArray) SetMetric(dimension int, value int64)

SetMetric 重置统计值

func (*ResMetricArray) SwapMetric

func (r *ResMetricArray) SwapMetric(dimension int, newValue int64) int64

SwapMetric .交换统计

type SliceWindow

type SliceWindow struct {
	// 滑窗所属的类型,一般为插件名
	Type string

	Lock *sync.Mutex
	// 周期开始时间
	PeriodStartTime int64
	// contains filtered or unexported fields
}

SliceWindow 滑窗

func NewSliceWindow

func NewSliceWindow(typ string, bucketCount int, bucketInterval time.Duration, metricSize int,
	curTime int64) *SliceWindow

NewSliceWindow 创建资源滑窗

func (*SliceWindow) AddGauge

func (s *SliceWindow) AddGauge(gauge model.InstanceGauge, operation AddBucketFunc) int64

AddGauge 添加统计数据

func (*SliceWindow) AddGaugeAdvance

func (s *SliceWindow) AddGaugeAdvance(gauge model.InstanceGauge, operation AddBucketFunc) (int64, int64)

AddGaugeAdvance 添加统计数据,返回就近的数据以及bucket起始时间

func (*SliceWindow) AddGaugeByValue

func (s *SliceWindow) AddGaugeByValue(value int64, curTime time.Time) int64

AddGaugeByValue 添加统计数据

func (*SliceWindow) AddGaugeByValueByMillTime

func (s *SliceWindow) AddGaugeByValueByMillTime(value int64, curTime int64) int64

AddGaugeByValueByMillTime 添加统计数据

func (*SliceWindow) AddHistoryMetric

func (s *SliceWindow) AddHistoryMetric(now time.Time, operation BucketOperation) (int64, bool)

AddHistoryMetric 添加历史数据 返回函数运行结果,以及是否命中

func (*SliceWindow) AddHistoryMetricByMillTime

func (s *SliceWindow) AddHistoryMetricByMillTime(now int64, operation BucketOperation) (int64, bool)

AddHistoryMetricByMillTime 添加历史数据

func (*SliceWindow) CalcMetrics

func (s *SliceWindow) CalcMetrics(dimension int, timeRange *TimeRange) int64

CalcMetrics 计算维度下所有的时间段的值之和

func (*SliceWindow) CalcMetricsInMultiDimensions

func (s *SliceWindow) CalcMetricsInMultiDimensions(dimensions []int, timeRange *TimeRange) []int64

CalcMetricsInMultiDimensions 计算多个维度下的统计值

func (*SliceWindow) CalcStartTime

func (s *SliceWindow) CalcStartTime(curTime int64) int64

CalcStartTime 计算对应bucket起始时间戳

func (*SliceWindow) GetBucketInterval

func (s *SliceWindow) GetBucketInterval() time.Duration

GetBucketInterval 获取滑桶的长度

func (*SliceWindow) GetLastUpdateTime

func (s *SliceWindow) GetLastUpdateTime() int64

GetLastUpdateTime 获取最近更新时间

func (*SliceWindow) IsMetricUpdate

func (s *SliceWindow) IsMetricUpdate() bool

IsMetricUpdate 判断是否在上次读取了数据后,又有数据更新

func (*SliceWindow) SetLastReadTime

func (s *SliceWindow) SetLastReadTime()

SetLastReadTime 设置最近读取时间

func (*SliceWindow) SetPeriodStart

func (s *SliceWindow) SetPeriodStart(now int64)

SetPeriodStart 根据当前时间设置周期开始时间

type TimeRange

type TimeRange struct {
	// Start 起始时间
	Start time.Time
	// End 结束时间
	End time.Time
	// Type 时间段类型
	Type IntervalType
}

TimeRange 时间段

func (*TimeRange) IsTimeInBucket

func (t *TimeRange) IsTimeInBucket(value time.Time) int

IsTimeInBucket 判断时间点是否在范围中

Jump to

Keyboard shortcuts

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