Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/supervisor/pkg/metrics/metrics.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package metrics
6
7
import (
8
"fmt"
9
10
"github.com/gitpod-io/gitpod/supervisor/pkg/shared"
11
"github.com/prometheus/client_golang/prometheus"
12
)
13
14
type SupervisorMetrics struct {
15
IDEReadyDurationTotal *prometheus.HistogramVec
16
InitializerHistogram *prometheus.HistogramVec
17
SSHTunnelOpenedTotal *prometheus.CounterVec
18
SSHTunnelClosedTotal *prometheus.CounterVec
19
}
20
21
func NewMetrics() *SupervisorMetrics {
22
return &SupervisorMetrics{
23
IDEReadyDurationTotal: prometheus.NewHistogramVec(prometheus.HistogramOpts{
24
Name: "supervisor_ide_ready_duration_total",
25
Help: "the IDE startup time",
26
Buckets: []float64{0.1, 0.5, 1, 1.5, 2, 2.5, 5, shared.IDEReadyDurationTotalMaxBucketSecond},
27
}, []string{"kind"}),
28
InitializerHistogram: prometheus.NewHistogramVec(prometheus.HistogramOpts{
29
Name: "supervisor_initializer_bytes_second",
30
Help: "initializer speed in bytes per second",
31
Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 12),
32
}, []string{"kind"}),
33
SSHTunnelOpenedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
34
Name: "supervisor_ssh_tunnel_opened_total",
35
Help: "Total number of SSH tunnels opened by the supervisor",
36
}, []string{}),
37
SSHTunnelClosedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
38
Name: "supervisor_ssh_tunnel_closed_total",
39
Help: "Total number of SSH tunnels closed by the supervisor",
40
}, []string{"code"}),
41
}
42
}
43
44
func (m *SupervisorMetrics) Register(registry *prometheus.Registry) error {
45
metrics := []prometheus.Collector{
46
m.IDEReadyDurationTotal,
47
m.InitializerHistogram,
48
m.SSHTunnelOpenedTotal,
49
m.SSHTunnelClosedTotal,
50
}
51
52
for _, metric := range metrics {
53
err := registry.Register(metric)
54
if err != nil {
55
return fmt.Errorf("failed to register metric: %w", err)
56
}
57
}
58
return nil
59
}
60
61