mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-16 02:47:03 +02:00
0ec3ff0b46
* move to contrib dir Co-authored-by: chenzhihui <zhihui_chen@foxmail.com>
36 lines
643 B
Go
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)
|
|
}
|