mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-30 04:31:03 +02:00
0ec3ff0b46
* move to contrib dir Co-authored-by: chenzhihui <zhihui_chen@foxmail.com>
32 lines
611 B
Go
32 lines
611 B
Go
package prometheus
|
|
|
|
import (
|
|
"github.com/go-kratos/kratos/v2/metrics"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var _ metrics.Observer = (*histogram)(nil)
|
|
|
|
type histogram struct {
|
|
hv *prometheus.HistogramVec
|
|
lvs []string
|
|
}
|
|
|
|
// NewHistogram new a prometheus histogram and returns Histogram.
|
|
func NewHistogram(hv *prometheus.HistogramVec) metrics.Observer {
|
|
return &histogram{
|
|
hv: hv,
|
|
}
|
|
}
|
|
|
|
func (h *histogram) With(lvs ...string) metrics.Observer {
|
|
return &histogram{
|
|
hv: h.hv,
|
|
lvs: lvs,
|
|
}
|
|
}
|
|
|
|
func (h *histogram) Observe(value float64) {
|
|
h.hv.WithLabelValues(h.lvs...).Observe(value)
|
|
}
|