mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License-AGPL.txt in the project root for license information.
|
|
|
|
package orchestrator
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
// RegisterMetrics registers the metrics of this builder
|
|
func (o *Orchestrator) RegisterMetrics(reg prometheus.Registerer) error {
|
|
err := reg.Register(o.metrics.imageBuildsDoneTotal)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = reg.Register(o.metrics.imageBuildsStartedTotal)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
const (
|
|
metricsNamespace = "gitpod"
|
|
metricsSubsystem = "image_builder"
|
|
)
|
|
|
|
type metrics struct {
|
|
imageBuildsDoneTotal *prometheus.CounterVec
|
|
imageBuildsStartedTotal prometheus.Counter
|
|
}
|
|
|
|
func newMetrics() *metrics {
|
|
return &metrics{
|
|
imageBuildsDoneTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: metricsNamespace,
|
|
Subsystem: metricsSubsystem,
|
|
Name: "builds_done_total",
|
|
}, []string{"success"}),
|
|
imageBuildsStartedTotal: prometheus.NewCounter(prometheus.CounterOpts{
|
|
Namespace: metricsNamespace,
|
|
Subsystem: metricsSubsystem,
|
|
Name: "builds_started_total",
|
|
}),
|
|
}
|
|
}
|
|
|
|
func (m *metrics) BuildDone(success bool) {
|
|
m.imageBuildsDoneTotal.WithLabelValues(strconv.FormatBool(success)).Inc()
|
|
}
|
|
|
|
func (m *metrics) BuildStarted() {
|
|
m.imageBuildsStartedTotal.Inc()
|
|
}
|