1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-16 02:47:03 +02:00
kratos/contrib/metrics/prometheus/counter.go
Windfarer 0ec3ff0b46
refactor: move plugins to contrib dir (#1399)
* move to contrib dir


Co-authored-by: chenzhihui <zhihui_chen@foxmail.com>
2021-09-01 13:40:14 +08:00

36 lines
643 B
Go

package prometheus
import (
"github.com/go-kratos/kratos/v2/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var _ metrics.Counter = (*counter)(nil)
type counter struct {
cv *prometheus.CounterVec
lvs []string
}
// NewCounter new a prometheus counter and returns Counter.
func NewCounter(cv *prometheus.CounterVec) metrics.Counter {
return &counter{
cv: cv,
}
}
func (c *counter) With(lvs ...string) metrics.Counter {
return &counter{
cv: c.cv,
lvs: lvs,
}
}
func (c *counter) Inc() {
c.cv.WithLabelValues(c.lvs...).Inc()
}
func (c *counter) Add(delta float64) {
c.cv.WithLabelValues(c.lvs...).Add(delta)
}