2019-02-19 23:56:41 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-02-28 07:07:13 +00:00
|
|
|
// +build !oss
|
|
|
|
|
2019-02-19 23:56:41 +00:00
|
|
|
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))
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|