This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaugegeo.go
65 lines (51 loc) · 1.57 KB
/
gaugegeo.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
54
55
56
57
58
59
60
61
62
63
64
65
package metrics
import (
"net"
)
type gaugeGeoImpl struct {
name string
collector *collector
labels []MetricLabel
}
func (g *gaugeGeoImpl) Increment(ip net.IP, labels ...MetricLabel) {
g.IncrementBy(ip, 1, labels...)
}
func (g *gaugeGeoImpl) IncrementBy(ip net.IP, by float64, labels ...MetricLabel) {
g.collector.mutex.Lock()
defer g.collector.mutex.Unlock()
realLabels := metricLabels(
append(g.labels, labels...),
).toMap()
realLabels["country"] = g.collector.geoIpLookupProvider.Lookup(ip)
value := g.collector.get(g.name, realLabels)
g.collector.set(g.name, realLabels, value+by)
}
func (g *gaugeGeoImpl) Decrement(ip net.IP, labels ...MetricLabel) {
g.DecrementBy(ip, 1, labels...)
}
func (g *gaugeGeoImpl) DecrementBy(ip net.IP, by float64, labels ...MetricLabel) {
g.collector.mutex.Lock()
defer g.collector.mutex.Unlock()
realLabels := metricLabels(
append(g.labels, labels...),
).toMap()
realLabels["country"] = g.collector.geoIpLookupProvider.Lookup(ip)
value := g.collector.get(g.name, realLabels)
g.collector.set(g.name, realLabels, value-by)
}
func (g *gaugeGeoImpl) Set(ip net.IP, value float64, labels ...MetricLabel) {
g.collector.mutex.Lock()
defer g.collector.mutex.Unlock()
realLabels := metricLabels(
append(g.labels, labels...),
).toMap()
realLabels["country"] = g.collector.geoIpLookupProvider.Lookup(ip)
g.collector.set(g.name, realLabels, value)
}
func (g *gaugeGeoImpl) WithLabels(labels ...MetricLabel) GeoGauge {
return &gaugeGeoImpl{
name: g.name,
collector: g.collector,
labels: append(g.labels, labels...),
}
}