Skip to content

Commit 8c4ddee

Browse files
authored
fix: convert prometheus metrics to use gauge type (#640)
1 parent 80f88c5 commit 8c4ddee

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

internal/metric/metric.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ func initRegistry() *Registry {
1818

1919
registry := &Registry{
2020
reg: prometheus.NewRegistry(),
21-
backupBytesProcessed: prometheus.NewSummaryVec(prometheus.SummaryOpts{
21+
backupBytesProcessed: prometheus.NewGaugeVec(prometheus.GaugeOpts{
2222
Name: "backrest_backup_bytes_processed",
2323
Help: "The total number of bytes processed during a backup",
2424
}, commonDims),
25-
backupBytesAdded: prometheus.NewSummaryVec(prometheus.SummaryOpts{
25+
backupBytesAdded: prometheus.NewGaugeVec(prometheus.GaugeOpts{
2626
Name: "backrest_backup_bytes_added",
2727
Help: "The total number of bytes added during a backup",
2828
}, commonDims),
29-
backupFileWarnings: prometheus.NewSummaryVec(prometheus.SummaryOpts{
29+
backupFileWarnings: prometheus.NewGaugeVec(prometheus.GaugeOpts{
3030
Name: "backrest_backup_file_warnings",
3131
Help: "The total number of file warnings during a backup",
3232
}, commonDims),
33-
tasksDuration: prometheus.NewSummaryVec(prometheus.SummaryOpts{
33+
tasksDuration: prometheus.NewGaugeVec(prometheus.GaugeOpts{
3434
Name: "backrest_tasks_duration_secs",
3535
Help: "The duration of a task in seconds",
3636
}, append(slices.Clone(commonDims), "task_type")),
@@ -55,10 +55,10 @@ func GetRegistry() *Registry {
5555

5656
type Registry struct {
5757
reg *prometheus.Registry
58-
backupBytesProcessed *prometheus.SummaryVec
59-
backupBytesAdded *prometheus.SummaryVec
60-
backupFileWarnings *prometheus.SummaryVec
61-
tasksDuration *prometheus.SummaryVec
58+
backupBytesProcessed *prometheus.GaugeVec
59+
backupBytesAdded *prometheus.GaugeVec
60+
backupFileWarnings *prometheus.GaugeVec
61+
tasksDuration *prometheus.GaugeVec
6262
tasksRun *prometheus.CounterVec
6363
}
6464

@@ -73,12 +73,13 @@ func (r *Registry) RecordTaskRun(repoID, planID, taskType string, duration_secs
7373
if planID == "" {
7474
planID = "_unassociated_"
7575
}
76+
r.tasksRun.DeletePartialMatch(prometheus.Labels{"repo_id": repoID, "plan_id": planID, "task_type": taskType})
7677
r.tasksRun.WithLabelValues(repoID, planID, taskType, status).Inc()
77-
r.tasksDuration.WithLabelValues(repoID, planID, taskType).Observe(duration_secs)
78+
r.tasksDuration.WithLabelValues(repoID, planID, taskType).Set(duration_secs)
7879
}
7980

8081
func (r *Registry) RecordBackupSummary(repoID, planID string, bytesProcessed, bytesAdded int64, fileWarnings int64) {
81-
r.backupBytesProcessed.WithLabelValues(repoID, planID).Observe(float64(bytesProcessed))
82-
r.backupBytesAdded.WithLabelValues(repoID, planID).Observe(float64(bytesAdded))
83-
r.backupFileWarnings.WithLabelValues(repoID, planID).Observe(float64(fileWarnings))
82+
r.backupBytesProcessed.WithLabelValues(repoID, planID).Set(float64(bytesProcessed))
83+
r.backupBytesAdded.WithLabelValues(repoID, planID).Set(float64(bytesAdded))
84+
r.backupFileWarnings.WithLabelValues(repoID, planID).Set(float64(fileWarnings))
8485
}

0 commit comments

Comments
 (0)