Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions monitor/prom/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions monitor/prom/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion run_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading