Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/image-builder-mk3/pkg/orchestrator/metrics.go
2500 views
1
// Copyright (c) 2021 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 orchestrator
6
7
import (
8
"strconv"
9
10
"github.com/prometheus/client_golang/prometheus"
11
)
12
13
// RegisterMetrics registers the metrics of this builder
14
func (o *Orchestrator) RegisterMetrics(reg prometheus.Registerer) error {
15
err := reg.Register(o.metrics.imageBuildsDoneTotal)
16
if err != nil {
17
return err
18
}
19
err = reg.Register(o.metrics.imageBuildsStartedTotal)
20
if err != nil {
21
return err
22
}
23
return nil
24
}
25
26
const (
27
metricsNamespace = "gitpod"
28
metricsSubsystem = "image_builder"
29
)
30
31
type metrics struct {
32
imageBuildsDoneTotal *prometheus.CounterVec
33
imageBuildsStartedTotal prometheus.Counter
34
}
35
36
func newMetrics() *metrics {
37
return &metrics{
38
imageBuildsDoneTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
39
Namespace: metricsNamespace,
40
Subsystem: metricsSubsystem,
41
Name: "builds_done_total",
42
}, []string{"success"}),
43
imageBuildsStartedTotal: prometheus.NewCounter(prometheus.CounterOpts{
44
Namespace: metricsNamespace,
45
Subsystem: metricsSubsystem,
46
Name: "builds_started_total",
47
}),
48
}
49
}
50
51
func (m *metrics) BuildDone(success bool) {
52
m.imageBuildsDoneTotal.WithLabelValues(strconv.FormatBool(success)).Inc()
53
}
54
55
func (m *metrics) BuildStarted() {
56
m.imageBuildsStartedTotal.Inc()
57
}
58
59