Skip to content

Commit

Permalink
metrics: export meta backup metrics (#4480)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored Mar 11, 2024
1 parent f80dd7a commit c4a7bd9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ func initBackgroundTasks(c *cli.Context, vfsConf *vfs.Config, metaConf *meta.Con
vfsConf.Port.ConsulAddr = c.String("consul")
}
if !metaConf.ReadOnly && !metaConf.NoBGJob && vfsConf.BackupMeta > 0 {
registerer.MustRegister(vfs.LastBackupTimeG)
registerer.MustRegister(vfs.LastBackupDurationG)
go vfs.Backup(m, blob, vfsConf.BackupMeta)
}
if !c.Bool("no-usage-report") {
Expand Down
14 changes: 14 additions & 0 deletions pkg/vfs/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ import (
"github.com/juicedata/juicefs/pkg/object"
osync "github.com/juicedata/juicefs/pkg/sync"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)

var (
LastBackupTimeG = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "last_successful_backup",
Help: "Last successful backup.",
})
LastBackupDurationG = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "last_backup_duration",
Help: "Last backup duration.",
})
)

// Backup metadata periodically in the object storage
Expand Down Expand Up @@ -66,10 +78,12 @@ func Backup(m meta.Meta, blob object.ObjectStorage, interval time.Duration) {
go cleanupBackups(blob, now)
logger.Debugf("backup metadata started")
if err = backup(m, blob, now); err == nil {
LastBackupTimeG.Set(float64(now.UnixNano()) / 1e9)
logger.Infof("backup metadata succeed, used %s", time.Since(now))
} else {
logger.Warnf("backup metadata failed: %s", err)
}
LastBackupDurationG.Set(time.Since(now).Seconds())
}
}
}
Expand Down

0 comments on commit c4a7bd9

Please sign in to comment.