mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(api): add prometheus metric coderd_workspace_builds_total (#6314)
This PR adds the prometheus metric coderd_workspace_builds_total. It measures the total number of workspace builds, along with a number of labels intended to be useful for an operator debugging a failed workspace build trying to discover the scope of the issue.
This commit is contained in:
@@ -157,6 +157,12 @@ func NewMetrics(reg prometheus.Registerer) Metrics {
|
||||
60 * 60, // 1hr
|
||||
},
|
||||
}, []string{"provisioner", "status"}),
|
||||
WorkspaceBuilds: auto.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "coderd",
|
||||
Subsystem: "", // Explicitly empty to make this a top-level metric.
|
||||
Name: "workspace_builds_total",
|
||||
Help: "The number of workspaces started, updated, or deleted.",
|
||||
}, []string{"owner_email", "workspace_name", "template_name", "template_version", "action", "status"}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ type Metrics struct {
|
||||
ConcurrentJobs *prometheus.GaugeVec
|
||||
// JobTimings also counts the total amount of jobs.
|
||||
JobTimings *prometheus.HistogramVec
|
||||
// WorkspaceBuilds counts workspace build successes and failures.
|
||||
WorkspaceBuilds *prometheus.CounterVec
|
||||
}
|
||||
|
||||
type JobUpdater interface {
|
||||
@@ -161,6 +163,16 @@ func (r *Runner) Run() {
|
||||
}
|
||||
|
||||
concurrentGauge.Dec()
|
||||
if build := r.job.GetWorkspaceBuild(); build != nil {
|
||||
r.metrics.WorkspaceBuilds.WithLabelValues(
|
||||
build.Metadata.WorkspaceOwnerEmail,
|
||||
build.Metadata.WorkspaceName,
|
||||
build.Metadata.TemplateName,
|
||||
build.Metadata.TemplateVersion,
|
||||
build.Metadata.WorkspaceTransition.String(),
|
||||
status,
|
||||
).Inc()
|
||||
}
|
||||
r.metrics.JobTimings.WithLabelValues(r.job.Provisioner, status).Observe(time.Since(start).Seconds())
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user