You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
926 B
45 lines
926 B
package datadog
|
|
|
|
import (
|
|
"gitea.drugeyes.vip/pharnexbase/kratos/v2/metrics"
|
|
)
|
|
|
|
var _ metrics.Counter = (*counter)(nil)
|
|
|
|
type counter struct {
|
|
opts options
|
|
name string
|
|
lvs []string
|
|
}
|
|
|
|
// NewCounter new a DataDog counter and returns Counter.
|
|
func NewCounter(name string, opts ...Option) metrics.Counter {
|
|
counterOpts := options{
|
|
sampleRate: 1,
|
|
client: defaultClient,
|
|
}
|
|
for _, o := range opts {
|
|
o(&counterOpts)
|
|
}
|
|
return &counter{
|
|
name: name,
|
|
opts: counterOpts,
|
|
}
|
|
}
|
|
|
|
// With is applied in kratos/middleware/metrics/metrics.go (method,path,code)
|
|
func (d *counter) With(values ...string) metrics.Counter {
|
|
return &counter{
|
|
name: d.name,
|
|
opts: d.opts,
|
|
lvs: withValues(d.opts.labels, values),
|
|
}
|
|
}
|
|
|
|
func (d *counter) Inc() {
|
|
_ = d.opts.client.Incr(d.name, d.lvs, d.opts.sampleRate)
|
|
}
|
|
|
|
func (d *counter) Add(delta float64) {
|
|
_ = d.opts.client.Count(d.name, int64(delta), d.lvs, d.opts.sampleRate)
|
|
}
|
|
|