Skip to content

Commit 43b6c84

Browse files
add version of restic to the Prometheus metrics (#495)
Add the restic version as a new metric `restic_build_info`. This allows to track the versions of both restic and resticprofile: PromQL can be used to identify outdated installations. refs #485
1 parent 763a2cd commit 43b6c84

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

monitor/prom/metrics.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ const (
2222
)
2323

2424
type Metrics struct {
25-
labels prometheus.Labels
26-
registry *prometheus.Registry
27-
info *prometheus.GaugeVec
28-
backup BackupMetrics
25+
labels prometheus.Labels
26+
registry *prometheus.Registry
27+
info *prometheus.GaugeVec
28+
resticInfo *prometheus.GaugeVec
29+
backup BackupMetrics
2930
}
3031

31-
func NewMetrics(profile, group, version string, configLabels map[string]string) *Metrics {
32+
func NewMetrics(profile, group, version string, resticversion string, configLabels map[string]string) *Metrics {
3233
// default labels for all metrics
3334
labels := prometheus.Labels{profileLabel: profile}
3435
if group != "" {
@@ -50,10 +51,18 @@ func NewMetrics(profile, group, version string, configLabels map[string]string)
5051
// send the information about the build right away
5152
p.info.With(mergeLabels(cloneLabels(labels), map[string]string{goVersionLabel: runtime.Version(), versionLabel: version})).Set(1)
5253

54+
p.resticInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
55+
Name: "restic_build_info",
56+
Help: "restic build information.",
57+
}, append(keys, versionLabel))
58+
// send the information about the build right away
59+
p.resticInfo.With(mergeLabels(cloneLabels(labels), map[string]string{versionLabel: resticversion})).Set(1)
60+
5361
p.backup = newBackupMetrics(keys)
5462

5563
registry.MustRegister(
5664
p.info,
65+
p.resticInfo,
5766
p.backup.duration,
5867
p.backup.filesNew,
5968
p.backup.filesChanged,

monitor/prom/metrics_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestSaveSingleBackup(t *testing.T) {
13-
p := NewMetrics("test", "", "", nil)
13+
p := NewMetrics("test", "", "", "", nil)
1414
p.BackupResults(StatusSuccess, monitor.Summary{
1515
Duration: 11 * time.Second,
1616
BytesAdded: 100,
@@ -21,7 +21,7 @@ func TestSaveSingleBackup(t *testing.T) {
2121
}
2222

2323
func TestSaveSingleBackupWithConfigLabel(t *testing.T) {
24-
p := NewMetrics("test", "", "", map[string]string{"test_label": "test_value"})
24+
p := NewMetrics("test", "", "", "", map[string]string{"test_label": "test_value"})
2525
p.BackupResults(StatusSuccess, monitor.Summary{
2626
Duration: 11 * time.Second,
2727
BytesAdded: 100,
@@ -32,7 +32,7 @@ func TestSaveSingleBackupWithConfigLabel(t *testing.T) {
3232
}
3333

3434
func TestSaveBackupGroup(t *testing.T) {
35-
p := NewMetrics("test", "group", "", nil)
35+
p := NewMetrics("test", "group", "", "", nil)
3636
p.BackupResults(StatusSuccess, monitor.Summary{
3737
Duration: 11 * time.Second,
3838
BytesAdded: 100,

run_profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func runProfile(ctx *Context) error {
193193
wrapper.addProgress(status.NewProgress(profile, status.NewStatus(profile.StatusFile)))
194194
}
195195
if profile.PrometheusPush != "" || profile.PrometheusSaveToFile != "" {
196-
wrapper.addProgress(prom.NewProgress(profile, prom.NewMetrics(profile.Name, ctx.request.group, version, profile.PrometheusLabels)))
196+
wrapper.addProgress(prom.NewProgress(profile, prom.NewMetrics(profile.Name, ctx.request.group, version, ctx.global.ResticVersion, profile.PrometheusLabels)))
197197
}
198198

199199
err = wrapper.runProfile()

0 commit comments

Comments
 (0)