-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcount.go
53 lines (45 loc) · 1.51 KB
/
count.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
50
51
52
53
package metrics
// MetricCount is the type of a "Count" metric.
//
// Count metric is an analog of prometheus' "Counter",
// see: https://godoc.org/github.com/prometheus/client_golang/prometheus#Counter
type MetricCount struct {
commonInt64
}
func (r *Registry) newMetricCount(key string, tags AnyTags) *MetricCount {
metric := metricCountPool.Get().(*MetricCount)
metric.init(r, key, tags)
return metric
}
func (m *MetricCount) init(r *Registry, key string, tags AnyTags) {
m.commonInt64.init(r, m, key, tags)
}
// Count returns a metric of type "MetricCount".
//
// For the same key and tags it will return the same metric.
//
// If there's no such metric then it will create it, register it in the registry and return it.
// If there's already such metric then it will just return the metric.
func Count(key string, tags AnyTags) *MetricCount {
return registry.Count(key, tags)
}
// Count returns a metric of type "MetricCount".
//
// For the same key and tags it will return the same metric.
//
// If there's no such metric then it will create it, register it in the registry and return it.
// If there's already such metric then it will just return the metric.
func (r *Registry) Count(key string, tags AnyTags) *MetricCount {
if IsDisabled() {
return (*MetricCount)(nil)
}
m := r.Get(TypeCount, key, tags)
if m != nil {
return m.(*MetricCount)
}
return r.newMetricCount(key, tags)
}
// GetType always returns "TypeCount" (because of type "MetricCount")
func (m *MetricCount) GetType() Type {
return TypeCount
}