diff --git a/monitor/prom/metrics.go b/monitor/prom/metrics.go index 8cc43491..f9f059ce 100644 --- a/monitor/prom/metrics.go +++ b/monitor/prom/metrics.go @@ -22,13 +22,14 @@ const ( ) type Metrics struct { - labels prometheus.Labels - registry *prometheus.Registry - info *prometheus.GaugeVec - backup BackupMetrics + labels prometheus.Labels + registry *prometheus.Registry + info *prometheus.GaugeVec + resticInfo *prometheus.GaugeVec + backup BackupMetrics } -func NewMetrics(profile, group, version string, configLabels map[string]string) *Metrics { +func NewMetrics(profile, group, version string, resticversion string, configLabels map[string]string) *Metrics { // default labels for all metrics labels := prometheus.Labels{profileLabel: profile} if group != "" { @@ -50,10 +51,18 @@ func NewMetrics(profile, group, version string, configLabels map[string]string) // send the information about the build right away p.info.With(mergeLabels(cloneLabels(labels), map[string]string{goVersionLabel: runtime.Version(), versionLabel: version})).Set(1) + p.resticInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "restic_build_info", + Help: "restic build information.", + }, append(keys, versionLabel)) + // send the information about the build right away + p.resticInfo.With(mergeLabels(cloneLabels(labels), map[string]string{versionLabel: resticversion})).Set(1) + p.backup = newBackupMetrics(keys) registry.MustRegister( p.info, + p.resticInfo, p.backup.duration, p.backup.filesNew, p.backup.filesChanged, diff --git a/monitor/prom/metrics_test.go b/monitor/prom/metrics_test.go index d992cda1..9e954d5b 100644 --- a/monitor/prom/metrics_test.go +++ b/monitor/prom/metrics_test.go @@ -10,7 +10,7 @@ import ( ) func TestSaveSingleBackup(t *testing.T) { - p := NewMetrics("test", "", "", nil) + p := NewMetrics("test", "", "", "", nil) p.BackupResults(StatusSuccess, monitor.Summary{ Duration: 11 * time.Second, BytesAdded: 100, @@ -21,7 +21,7 @@ func TestSaveSingleBackup(t *testing.T) { } func TestSaveSingleBackupWithConfigLabel(t *testing.T) { - p := NewMetrics("test", "", "", map[string]string{"test_label": "test_value"}) + p := NewMetrics("test", "", "", "", map[string]string{"test_label": "test_value"}) p.BackupResults(StatusSuccess, monitor.Summary{ Duration: 11 * time.Second, BytesAdded: 100, @@ -32,7 +32,7 @@ func TestSaveSingleBackupWithConfigLabel(t *testing.T) { } func TestSaveBackupGroup(t *testing.T) { - p := NewMetrics("test", "group", "", nil) + p := NewMetrics("test", "group", "", "", nil) p.BackupResults(StatusSuccess, monitor.Summary{ Duration: 11 * time.Second, BytesAdded: 100, diff --git a/run_profile.go b/run_profile.go index 9d55e376..c7dffb8c 100644 --- a/run_profile.go +++ b/run_profile.go @@ -193,7 +193,7 @@ func runProfile(ctx *Context) error { wrapper.addProgress(status.NewProgress(profile, status.NewStatus(profile.StatusFile))) } if profile.PrometheusPush != "" || profile.PrometheusSaveToFile != "" { - wrapper.addProgress(prom.NewProgress(profile, prom.NewMetrics(profile.Name, ctx.request.group, version, profile.PrometheusLabels))) + wrapper.addProgress(prom.NewProgress(profile, prom.NewMetrics(profile.Name, ctx.request.group, version, ctx.global.ResticVersion, profile.PrometheusLabels))) } err = wrapper.runProfile()