Skip to content

Commit bc8f789

Browse files
add version of restic to the Prometheus metrics
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 e991cfd commit bc8f789

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

monitor/prom/metrics.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@ import (
1313
)
1414

1515
const (
16-
namespace = "resticprofile"
17-
backup = "backup"
18-
groupLabel = "group"
19-
profileLabel = "profile"
20-
goVersionLabel = "goversion"
21-
versionLabel = "version"
16+
namespace = "resticprofile"
17+
backup = "backup"
18+
groupLabel = "group"
19+
profileLabel = "profile"
20+
goVersionLabel = "goversion"
21+
versionLabel = "version"
22+
resticVersionLabel = "resticversion"
2223
)
2324

2425
type Metrics struct {
25-
labels prometheus.Labels
26-
registry *prometheus.Registry
27-
info *prometheus.GaugeVec
28-
backup BackupMetrics
26+
labels prometheus.Labels
27+
registry *prometheus.Registry
28+
info *prometheus.GaugeVec
29+
resticInfo *prometheus.GaugeVec
30+
backup BackupMetrics
2931
}
3032

31-
func NewMetrics(profile, group, version string, configLabels map[string]string) *Metrics {
33+
func NewMetrics(profile, group, version string, resticversion string, configLabels map[string]string) *Metrics {
3234
// default labels for all metrics
3335
labels := prometheus.Labels{profileLabel: profile}
3436
if group != "" {
@@ -50,10 +52,18 @@ func NewMetrics(profile, group, version string, configLabels map[string]string)
5052
// send the information about the build right away
5153
p.info.With(mergeLabels(cloneLabels(labels), map[string]string{goVersionLabel: runtime.Version(), versionLabel: version})).Set(1)
5254

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

5564
registry.MustRegister(
5665
p.info,
66+
p.resticInfo,
5767
p.backup.duration,
5868
p.backup.filesNew,
5969
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)