-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrouter.go
67 lines (56 loc) · 1.85 KB
/
router.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
66
67
package metrics
import (
"crypto/tls"
metrics "github.com/rcrowley/go-metrics"
)
// NewRouterMetrics creates a RouterMetrics using the injected registry
func NewRouterMetrics(parent *metrics.Registry) *RouterMetrics {
r := metrics.NewPrefixedChildRegistry(*parent, "router.")
return &RouterMetrics{
ProxyMetrics{r},
metrics.NewRegisteredCounter("connected", r),
metrics.NewRegisteredCounter("disconnected", r),
metrics.NewRegisteredCounter("connected-total", r),
metrics.NewRegisteredCounter("disconnected-total", r),
metrics.NewRegisteredGauge("connected-gauge", r),
metrics.NewRegisteredGauge("disconnected-gauge", r),
}
}
// RouterMetrics is the metrics collector for the router package
type RouterMetrics struct {
ProxyMetrics
connected metrics.Counter
disconnected metrics.Counter
connectedTotal metrics.Counter
disconnectedTotal metrics.Counter
connectedGauge metrics.Gauge
disconnectedGauge metrics.Gauge
}
// Connection adds one to the internal connected counter
func (rm *RouterMetrics) Connection(TLS *tls.ConnectionState) {
rm.connected.Inc(1)
if TLS == nil {
return
}
rm.Counter("tls_version", tlsVersion[TLS.Version], "count").Inc(1)
rm.Counter("tls_cipher", tlsCipherSuite[TLS.CipherSuite], "count").Inc(1)
}
// Disconnection adds one to the internal disconnected counter
func (rm *RouterMetrics) Disconnection() {
rm.disconnected.Inc(1)
}
func (rm *RouterMetrics) Aggregate() {
con := rm.connected.Count()
rm.connectedGauge.Update(con)
rm.connectedTotal.Inc(con)
rm.connected.Clear()
discon := rm.disconnected.Count()
rm.disconnectedGauge.Update(discon)
rm.disconnectedTotal.Inc(discon)
rm.disconnected.Clear()
}
func (rm *RouterMetrics) RegisterResponseWriterMetrics(name string) {
rm.Counter("response", name, "status")
rm.Histogram("response", name, "size")
rm.Histogram("response", name, "time")
}