1 Star 0 Fork 2

QunXiongZhuLu / kratos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
point_gauge.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
felixhao 提交于 2019-04-12 21:07 . add wiki
package metric
var _ Metric = &pointGauge{}
var _ Aggregation = &pointGauge{}
// PointGauge represents a ring window.
// Every buckets within the window contains one point.
// When the window is full, the earliest point will be overwrite.
type PointGauge interface {
Aggregation
Metric
// Reduce applies the reduction function to all buckets within the window.
Reduce(func(Iterator) float64) float64
}
// PointGaugeOpts contains the arguments for creating PointGauge.
type PointGaugeOpts struct {
// Size represents the bucket size within the window.
Size int
}
type pointGauge struct {
policy *PointPolicy
}
// NewPointGauge creates a new PointGauge based on PointGaugeOpts.
func NewPointGauge(opts PointGaugeOpts) PointGauge {
window := NewWindow(WindowOpts{Size: opts.Size})
policy := NewPointPolicy(window)
return &pointGauge{
policy: policy,
}
}
func (r *pointGauge) Add(val int64) {
r.policy.Append(float64(val))
}
func (r *pointGauge) Reduce(f func(Iterator) float64) float64 {
return r.policy.Reduce(f)
}
func (r *pointGauge) Avg() float64 {
return r.policy.Reduce(Avg)
}
func (r *pointGauge) Min() float64 {
return r.policy.Reduce(Min)
}
func (r *pointGauge) Max() float64 {
return r.policy.Reduce(Max)
}
func (r *pointGauge) Sum() float64 {
return r.policy.Reduce(Sum)
}
func (r *pointGauge) Value() int64 {
return int64(r.Sum())
}
1
https://gitee.com/QunXiongZhuLu/kratos.git
git@gitee.com:QunXiongZhuLu/kratos.git
QunXiongZhuLu
kratos
kratos
v0.6.2

搜索帮助