Skip to content

Commit f18f7ca

Browse files
committed
[supervisor] add ssh tunnel metrics
1 parent f690f87 commit f18f7ca

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

components/supervisor/pkg/metrics/metrics.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
type SupervisorMetrics struct {
1414
IDEReadyDurationTotal *prometheus.HistogramVec
1515
InitializerHistogram *prometheus.HistogramVec
16+
SSHTunnelOpenedTotal *prometheus.CounterVec
17+
SSHTunnelClosedTotal *prometheus.CounterVec
1618
}
1719

1820
func NewMetrics() *SupervisorMetrics {
@@ -27,6 +29,14 @@ func NewMetrics() *SupervisorMetrics {
2729
Help: "initializer speed in bytes per second",
2830
Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 12),
2931
}, []string{"kind"}),
32+
SSHTunnelOpenedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
33+
Name: "supervisor_ssh_tunnel_opened_total",
34+
Help: "Total number of SSH tunnels opened by the supervisor",
35+
}, []string{}),
36+
SSHTunnelClosedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
37+
Name: "supervisor_ssh_tunnel_closed_total",
38+
Help: "Total number of SSH tunnels closed by the supervisor",
39+
}, []string{"code"}),
3040
}
3141
}
3242

components/supervisor/pkg/metrics/reporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func NewGrpcMetricsReporter(gitpodHost string) *GrpcMetricsReporter {
4343
"supervisor_initializer_bytes_second": true,
4444
"supervisor_client_handled_total": true,
4545
"supervisor_client_handling_seconds": true,
46+
"supervisor_ssh_tunnel_opened_total": true,
47+
"supervisor_ssh_tunnel_closed_total": true,
4648
},
4749
values: make(map[string]float64),
4850
addCounter: func(name string, labels map[string]string, value uint64) {

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func Run(options ...RunOption) {
418418
}
419419

420420
wg.Add(1)
421-
go startAPIEndpoint(ctx, cfg, &wg, apiServices, tunneledPortsService, metricsReporter, apiEndpointOpts...)
421+
go startAPIEndpoint(ctx, cfg, &wg, apiServices, tunneledPortsService, metricsReporter, supervisorMetrics, apiEndpointOpts...)
422422

423423
wg.Add(1)
424424
go startSSHServer(ctx, cfg, &wg)
@@ -1187,7 +1187,7 @@ func isBlacklistedEnvvar(name string) bool {
11871187
return false
11881188
}
11891189

1190-
func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, services []RegisterableService, tunneled *ports.TunneledPortsService, metricsReporter *metrics.GrpcMetricsReporter, opts ...grpc.ServerOption) {
1190+
func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, services []RegisterableService, tunneled *ports.TunneledPortsService, metricsReporter *metrics.GrpcMetricsReporter, supervisorMetrics *metrics.SupervisorMetrics, opts ...grpc.ServerOption) {
11911191
defer wg.Done()
11921192
defer log.Debug("startAPIEndpoint shutdown")
11931193

@@ -1308,6 +1308,16 @@ func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, serv
13081308
tunnelOverWebSocket(tunneled, conn)
13091309
}))
13101310
routes.Handle("/_supervisor/tunnel/ssh", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
1311+
supervisorMetrics.SSHTunnelOpenedTotal.WithLabelValues().Inc()
1312+
defer func() {
1313+
code := "unknown"
1314+
if err != nil {
1315+
if e, ok := err.(*websocket.CloseError); ok {
1316+
code = strconv.Itoa(e.Code)
1317+
}
1318+
}
1319+
supervisorMetrics.SSHTunnelClosedTotal.WithLabelValues(code).Inc()
1320+
}()
13111321
wsConn, err := upgrader.Upgrade(rw, r, nil)
13121322
if err != nil {
13131323
log.WithError(err).Error("tunnel ssh: upgrade to the WebSocket protocol failed")

install/installer/pkg/components/ide-metrics/configmap.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,22 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
336336
},
337337
},
338338
},
339+
{
340+
Name: "supervisor_ssh_tunnel_opened_total",
341+
Help: "Total number of SSH tunnels opened by the supervisor",
342+
Labels: []config.LabelAllowList{},
343+
},
344+
{
345+
Name: "supervisor_ssh_tunnel_closed_total",
346+
Help: "Total number of SSH tunnels closed by the supervisor",
347+
Labels: []config.LabelAllowList{
348+
{
349+
Name: "code",
350+
AllowValues: []string{"*"},
351+
DefaultValue: "unknown",
352+
},
353+
},
354+
},
339355
}
340356

341357
histogramMetrics := []config.HistogramMetricsConfiguration{

0 commit comments

Comments
 (0)