Path: blob/main/components/supervisor/pkg/metrics/metrics.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package metrics56import (7"fmt"89"github.com/gitpod-io/gitpod/supervisor/pkg/shared"10"github.com/prometheus/client_golang/prometheus"11)1213type SupervisorMetrics struct {14IDEReadyDurationTotal *prometheus.HistogramVec15InitializerHistogram *prometheus.HistogramVec16SSHTunnelOpenedTotal *prometheus.CounterVec17SSHTunnelClosedTotal *prometheus.CounterVec18}1920func NewMetrics() *SupervisorMetrics {21return &SupervisorMetrics{22IDEReadyDurationTotal: prometheus.NewHistogramVec(prometheus.HistogramOpts{23Name: "supervisor_ide_ready_duration_total",24Help: "the IDE startup time",25Buckets: []float64{0.1, 0.5, 1, 1.5, 2, 2.5, 5, shared.IDEReadyDurationTotalMaxBucketSecond},26}, []string{"kind"}),27InitializerHistogram: prometheus.NewHistogramVec(prometheus.HistogramOpts{28Name: "supervisor_initializer_bytes_second",29Help: "initializer speed in bytes per second",30Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 12),31}, []string{"kind"}),32SSHTunnelOpenedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{33Name: "supervisor_ssh_tunnel_opened_total",34Help: "Total number of SSH tunnels opened by the supervisor",35}, []string{}),36SSHTunnelClosedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{37Name: "supervisor_ssh_tunnel_closed_total",38Help: "Total number of SSH tunnels closed by the supervisor",39}, []string{"code"}),40}41}4243func (m *SupervisorMetrics) Register(registry *prometheus.Registry) error {44metrics := []prometheus.Collector{45m.IDEReadyDurationTotal,46m.InitializerHistogram,47m.SSHTunnelOpenedTotal,48m.SSHTunnelClosedTotal,49}5051for _, metric := range metrics {52err := registry.Register(metric)53if err != nil {54return fmt.Errorf("failed to register metric: %w", err)55}56}57return nil58}596061