harness-drone/metric/builds.go
2019-02-27 23:07:13 -08:00

52 lines
1.3 KiB
Go

// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package metric
import (
"github.com/drone/drone/core"
"github.com/prometheus/client_golang/prometheus"
)
// BuildCount provides metrics for build counts.
func BuildCount(builds core.BuildStore) {
prometheus.MustRegister(
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Name: "drone_build_count",
Help: "Total number of builds.",
}, func() float64 {
i, _ := builds.Count(noContext)
return float64(i)
}),
)
}
// PendingBuildCount provides metrics for pending build counts.
func PendingBuildCount(builds core.BuildStore) {
prometheus.MustRegister(
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Name: "drone_pending_builds",
Help: "Total number of pending builds.",
}, func() float64 {
list, _ := builds.Pending(noContext)
return float64(len(list))
}),
)
}
// RunningBuildCount provides metrics for running build counts.
func RunningBuildCount(builds core.BuildStore) {
prometheus.MustRegister(
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Name: "drone_running_builds",
Help: "Total number of running builds.",
}, func() float64 {
list, _ := builds.Running(noContext)
return float64(len(list))
}),
)
}