Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/public-api-server/pkg/proxy/prometheusmetrics.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 proxy
6
7
import (
8
"strconv"
9
"time"
10
11
"github.com/prometheus/client_golang/prometheus"
12
)
13
14
func reportConnectionDuration(d time.Duration) {
15
proxyConnectionCreateDurationSeconds.Observe(d.Seconds())
16
}
17
18
var (
19
proxyConnectionCreateDurationSeconds = prometheus.NewHistogram(prometheus.HistogramOpts{
20
Namespace: "gitpod",
21
Subsystem: "public_api",
22
Name: "proxy_connection_create_duration_seconds",
23
Help: "Histogram of connection time in seconds",
24
})
25
26
connectionPoolSize = prometheus.NewGauge(prometheus.GaugeOpts{
27
Namespace: "gitpod",
28
Subsystem: "public_api",
29
Name: "proxy_connection_pool_size",
30
Help: "Gauge of connections in connection pool",
31
})
32
33
connectionPoolCacheOutcome = prometheus.NewCounterVec(prometheus.CounterOpts{
34
Namespace: "gitpod",
35
Subsystem: "public_api",
36
Name: "proxy_connection_pool_cache_outcomes_total",
37
Help: "Counter of cachce accesses",
38
}, []string{"hit"})
39
)
40
41
func RegisterMetrics(registry *prometheus.Registry) {
42
registry.MustRegister(proxyConnectionCreateDurationSeconds)
43
registry.MustRegister(connectionPoolSize)
44
registry.MustRegister(connectionPoolCacheOutcome)
45
}
46
47
func reportCacheOutcome(hit bool) {
48
connectionPoolCacheOutcome.WithLabelValues(strconv.FormatBool(hit)).Inc()
49
}
50
51