tangled
alpha
login
or
join now
sr.aux1.dev
/
tsproxy
2
fork
atom
HTTP reverse proxy for Tailscale
2
fork
atom
overview
issues
pulls
1
pipelines
add upstream label to all http metrics
Simon Rozet
3 years ago
e4cfe731
66d4d0e0
+15
-16
1 changed file
expand all
collapse all
unified
split
main.go
+15
-16
main.go
reviewed
···
26
26
)
27
27
28
28
var (
29
29
-
requestsInFlight = promauto.NewGauge(prometheus.GaugeOpts{
30
30
-
Namespace: "tsproxy",
31
31
-
Name: "requests_in_flight",
32
32
-
Help: "Number of requests currently being served by the server.",
33
33
-
})
29
29
+
requestsInFlight = promauto.NewGaugeVec(
30
30
+
prometheus.GaugeOpts{
31
31
+
Namespace: "tsproxy",
32
32
+
Name: "requests_in_flight",
33
33
+
Help: "Number of requests currently being served by the server.",
34
34
+
},
35
35
+
[]string{"upstream"},
36
36
+
)
34
37
35
38
requests = promauto.NewCounterVec(
36
39
prometheus.CounterOpts{
···
38
41
Name: "requests_total",
39
42
Help: "Number of requests received by the server.",
40
43
},
41
41
-
[]string{"code", "method"},
44
44
+
[]string{"upstream", "code", "method"},
42
45
)
43
46
44
47
duration = promauto.NewHistogramVec(
···
48
51
Help: "A histogram of latencies for requests handled by the server.",
49
52
NativeHistogramBucketFactor: 1.1,
50
53
},
51
51
-
[]string{"code", "method"},
54
54
+
[]string{"upstream", "code", "method"},
52
55
)
53
56
)
54
57
···
152
155
g.Add(run.SignalHandler(ctx, os.Interrupt, syscall.SIGTERM))
153
156
154
157
{
155
155
-
ln, err := net.Listen("tcp", net.JoinHostPort(st.Self.TailscaleIPs[0].String(), strconv.Itoa(*port)))
158
158
+
p := strconv.Itoa(*port)
159
159
+
ln, err := net.Listen("tcp", net.JoinHostPort(st.Self.TailscaleIPs[0].String(), p))
156
160
if err != nil {
157
161
return fmt.Errorf("listen on %d: %w", *port, err)
158
162
}
159
163
defer ln.Close()
160
160
-
161
161
-
_, p, err := net.SplitHostPort(ln.Addr().String())
162
162
-
if err != nil {
163
163
-
return err
164
164
-
}
165
164
166
165
http.Handle("/metrics", promhttp.Handler())
167
166
http.Handle("/sd", serveDiscovery(net.JoinHostPort(st.Self.DNSName, p), targets))
···
219
218
220
219
srv := &http.Server{
221
220
TLSConfig: &tls.Config{GetCertificate: lc.GetCertificate},
222
222
-
Handler: promhttp.InstrumentHandlerInFlight(requestsInFlight,
223
223
-
promhttp.InstrumentHandlerDuration(duration,
224
224
-
promhttp.InstrumentHandlerCounter(requests,
221
221
+
Handler: promhttp.InstrumentHandlerInFlight(requestsInFlight.With(prometheus.Labels{"upstream": upstream.name}),
222
222
+
promhttp.InstrumentHandlerDuration(duration.MustCurryWith(prometheus.Labels{"upstream": upstream.name}),
223
223
+
promhttp.InstrumentHandlerCounter(requests.MustCurryWith(prometheus.Labels{"upstream": upstream.name}),
225
224
newReverseProxy(log.With(slog.String("upstream", upstream.name)), lc, upstream.backend)))),
226
225
}
227
226