1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
go-metrics-wrapper.go 2.93 KB
一键复制 编辑 原始数据 按行查看 历史
package adapter
import (
"github.com/elastic/beats/libbeat/monitoring"
metrics "github.com/rcrowley/go-metrics"
)
// go-metrics wrapper interface required to unpack the original metric
type goMetricsWrapper interface {
wrapped() interface{}
}
// go-metrics wrappers
type (
goMetricsCounter struct{ c metrics.Counter }
goMetricsGauge struct{ g metrics.Gauge }
goMetricsGaugeFloat64 struct{ g metrics.GaugeFloat64 }
goMetricsFuncGauge struct{ g metrics.FunctionalGauge }
goMetricsFuncGaugeFloat struct {
g metrics.FunctionalGaugeFloat64
}
goMetricsHistogram struct{ h metrics.Histogram }
goMetricsMeter struct{ m metrics.Meter }
)
// goMetricsWrap tries to wrap a metric for use with monitoring package.
func goMetricsWrap(metric interface{}) (monitoring.Var, bool) {
switch v := metric.(type) {
case *metrics.StandardCounter:
return goMetricsCounter{v}, true
case *metrics.StandardGauge:
return goMetricsGauge{v}, true
case *metrics.StandardGaugeFloat64:
return goMetricsGaugeFloat64{v}, true
case metrics.FunctionalGauge:
return goMetricsFuncGauge{v}, true
case metrics.FunctionalGaugeFloat64:
return goMetricsFuncGaugeFloat{v}, true
case *metrics.StandardHistogram:
return goMetricsHistogram{v}, true
case *metrics.StandardMeter:
return goMetricsMeter{v}, true
}
return nil, false
}
func (w goMetricsCounter) wrapped() interface{} { return w.c }
func (w goMetricsCounter) Get() int64 { return w.c.Count() }
func (w goMetricsCounter) Visit(_ monitoring.Mode, vs monitoring.Visitor) {
vs.OnInt(w.Get())
}
func (w goMetricsGauge) wrapped() interface{} { return w.g }
func (w goMetricsGauge) Get() int64 { return w.g.Value() }
func (w goMetricsGauge) Visit(_ monitoring.Mode, vs monitoring.Visitor) {
vs.OnInt(w.Get())
}
func (w goMetricsGaugeFloat64) wrapped() interface{} { return w.g }
func (w goMetricsGaugeFloat64) Get() float64 { return w.g.Value() }
func (w goMetricsGaugeFloat64) Visit(_ monitoring.Mode, vs monitoring.Visitor) {
vs.OnFloat(w.Get())
}
func (w goMetricsFuncGauge) wrapped() interface{} { return w.g }
func (w goMetricsFuncGauge) Get() int64 { return w.g.Value() }
func (w goMetricsFuncGauge) Visit(_ monitoring.Mode, vs monitoring.Visitor) {
vs.OnInt(w.Get())
}
func (w goMetricsFuncGaugeFloat) wrapped() interface{} { return w.g }
func (w goMetricsFuncGaugeFloat) Get() float64 { return w.g.Value() }
func (w goMetricsFuncGaugeFloat) Visit(_ monitoring.Mode, vs monitoring.Visitor) {
vs.OnFloat(w.Get())
}
func (w goMetricsHistogram) wrapped() interface{} { return w.h }
func (w goMetricsHistogram) Get() int64 { return w.h.Sum() }
func (w goMetricsHistogram) Visit(_ monitoring.Mode, vs monitoring.Visitor) {
vs.OnInt(w.Get())
}
func (w goMetricsMeter) wrapped() interface{} { return w.m }
func (w goMetricsMeter) Get() int64 { return w.m.Count() }
func (w goMetricsMeter) Visit(_ monitoring.Mode, vs monitoring.Visitor) {
vs.OnInt(w.Get())
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.4.0

搜索帮助