-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrace.go
More file actions
89 lines (81 loc) · 2.91 KB
/
Copy pathtrace.go
File metadata and controls
89 lines (81 loc) · 2.91 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package prometheus
import (
"context"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/gol4ng/httpware/metrics"
)
func NewInstrumentTrace(config ConfigTrace) *metrics.InstrumentTrace {
clientDetailsLatencyVec := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: config.Namespace,
Subsystem: "http",
Name: "details_duration_seconds",
Help: "Trace request latency histogram.",
Buckets: config.DetailLatencyBuckets,
},
[]string{"event"},
)
clientDNSLatencyVec := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: config.Namespace,
Subsystem: "http",
Name: "dns_duration_seconds",
Help: "Trace dns latency histogram.",
Buckets: config.DNSLatencyBuckets,
},
[]string{"event"},
)
clientTLSLatencyVec := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: config.Namespace,
Subsystem: "http",
Name: "tls_duration_seconds",
Help: "Trace tls latency histogram.",
Buckets: config.TLSLatencyBuckets,
},
[]string{"event"},
)
confTrace := &metrics.InstrumentTrace{}
confTrace.DNSStart = func(ctx context.Context, t time.Duration) {
clientDNSLatencyVec.WithLabelValues("dns_start")
}
confTrace.DNSDone = func(ctx context.Context, t time.Duration) {
clientDNSLatencyVec.WithLabelValues("dns_done")
}
confTrace.ConnectStart = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("connect_start")
}
confTrace.ConnectDone = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("connect_done")
}
confTrace.TLSHandshakeStart = func(ctx context.Context, t time.Duration) {
clientTLSLatencyVec.WithLabelValues("tls_handshake_start")
}
confTrace.TLSHandshakeDone = func(ctx context.Context, t time.Duration) {
clientTLSLatencyVec.WithLabelValues("tls_handshake_done")
}
confTrace.GotConn = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("got_conn")
}
confTrace.PutIdleConn = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("put_idle_conn")
}
confTrace.WroteHeaders = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("wrote_headers")
}
confTrace.WroteRequest = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("wrote_request")
}
confTrace.Got100Continue = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("got_100_continue")
}
confTrace.Wait100Continue = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("wait_100_continue")
}
confTrace.GotFirstResponseByte = func(ctx context.Context, t time.Duration) {
clientDetailsLatencyVec.WithLabelValues("got_first_response_byte")
}
prometheus.MustRegister(clientDetailsLatencyVec, clientDNSLatencyVec, clientTLSLatencyVec)
return confTrace
}