forked from Meituan-Dianping/cat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric_helper.go
49 lines (38 loc) · 866 Bytes
/
metric_helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cat
import (
"time"
)
type MetricHelper interface {
AddTag(key, val string) MetricHelper
Count(int)
Duration(time.Duration)
}
type catMetricHelper struct {
name string
tags map[string]string
}
type nullMetricHelper struct {
}
func (h *nullMetricHelper) AddTag(key, val string) MetricHelper {
return h
}
func (h *nullMetricHelper) Count(count int) {
}
func (h *nullMetricHelper) Duration(duration time.Duration) {
}
func newMetricHelper(name string) MetricHelper {
return &catMetricHelper{
name: name,
tags: make(map[string]string),
}
}
func (h *catMetricHelper) AddTag(key, val string) MetricHelper {
h.tags[key] = val
return h
}
func (h *catMetricHelper) Count(count int) {
aggregator.metric.AddCount(h.name, count)
}
func (h *catMetricHelper) Duration(duration time.Duration) {
aggregator.metric.AddDuration(h.name, duration)
}