1 Star 0 Fork 2

QunXiongZhuLu / kratos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
histogram.go 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
shunza 提交于 2019-07-20 19:38 . user new prometheus.
package metric
import (
"github.com/prometheus/client_golang/prometheus"
)
// HistogramVecOpts is histogram vector opts.
type HistogramVecOpts struct {
Namespace string
Subsystem string
Name string
Help string
Labels []string
Buckets []float64
}
// HistogramVec gauge vec.
type HistogramVec interface {
// Observe adds a single observation to the histogram.
Observe(v int64, labels ...string)
}
// Histogram prom histogram collection.
type promHistogramVec struct {
histogram *prometheus.HistogramVec
}
// NewHistogramVec new a histogram vec.
func NewHistogramVec(cfg *HistogramVecOpts) HistogramVec {
if cfg == nil {
return nil
}
vec := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: cfg.Namespace,
Subsystem: cfg.Subsystem,
Name: cfg.Name,
Help: cfg.Help,
Buckets: cfg.Buckets,
}, cfg.Labels)
prometheus.MustRegister(vec)
return &promHistogramVec{
histogram: vec,
}
}
// Timing adds a single observation to the histogram.
func (histogram *promHistogramVec) Observe(v int64, labels ...string) {
histogram.histogram.WithLabelValues(labels...).Observe(float64(v))
}
1
https://gitee.com/QunXiongZhuLu/kratos.git
git@gitee.com:QunXiongZhuLu/kratos.git
QunXiongZhuLu
kratos
kratos
v0.6.2

搜索帮助