"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
stats: add counter for deleted directories - fixes #4676
Nick Craig-Woodaf55a74bd2d2
diff --git a/fs/accounting/prometheus.go b/fs/accounting/prometheus.goindex e34bc0146..c9d165c95 100644--- a/fs/accounting/prometheus.go+++ b/fs/accounting/prometheus.go@@ -14,6 +14,7 @@ type RcloneCollector struct {numOfCheckFiles *prometheus.DesctransferredFiles *prometheus.Descdeletes *prometheus.Desc+ deletedDirs *prometheus.Descrenames *prometheus.DescfatalError *prometheus.DescretryError *prometheus.Desc@@ -46,6 +47,10 @@ func NewRcloneCollector() *RcloneCollector {"Total number of files deleted",nil, nil,),+ deletedDirs: prometheus.NewDesc(namespace+"dirs_deleted_total",+ "Total number of directories deleted",+ nil, nil,+ ),renames: prometheus.NewDesc(namespace+"files_renamed_total","Total number of files renamed",nil, nil,@@ -69,6 +74,7 @@ func (c *RcloneCollector) Describe(ch chan<- *prometheus.Desc) {ch <- c.numOfCheckFilesch <- c.transferredFilesch <- c.deletes+ ch <- c.deletedDirsch <- c.renamesch <- c.fatalErrorch <- c.retryError@@ -85,6 +91,7 @@ func (c *RcloneCollector) Collect(ch chan<- prometheus.Metric) {ch <- prometheus.MustNewConstMetric(c.numOfCheckFiles, prometheus.CounterValue, float64(s.checks))ch <- prometheus.MustNewConstMetric(c.transferredFiles, prometheus.CounterValue, float64(s.transfers))ch <- prometheus.MustNewConstMetric(c.deletes, prometheus.CounterValue, float64(s.deletes))+ ch <- prometheus.MustNewConstMetric(c.deletedDirs, prometheus.CounterValue, float64(s.deletedDirs))ch <- prometheus.MustNewConstMetric(c.renames, prometheus.CounterValue, float64(s.renames))ch <- prometheus.MustNewConstMetric(c.fatalError, prometheus.GaugeValue, bool2Float(s.fatalError))ch <- prometheus.MustNewConstMetric(c.retryError, prometheus.GaugeValue, bool2Float(s.retryError))diff --git a/fs/accounting/stats.go b/fs/accounting/stats.goindex 0c5ee2903..1f4992897 100644--- a/fs/accounting/stats.go+++ b/fs/accounting/stats.go@@ -40,6 +40,7 @@ type StatsInfo struct {renameQueue intrenameQueueSize int64deletes int64+ deletedDirs int64inProgress *inProgressstartedTransfers []*Transfer // currently active transfersoldTimeRanges timeRanges // a merged list of time ranges for the transfers@@ -68,6 +69,7 @@ func (s *StatsInfo) RemoteStats() (out rc.Params, err error) {out["checks"] = s.checksout["transfers"] = s.transfersout["deletes"] = s.deletes+ out["deletedDirs"] = s.deletedDirsout["renames"] = s.renamesout["transferTime"] = s.totalDuration().Seconds()out["elapsedTime"] = time.Since(startTime).Seconds()@@ -310,8 +312,8 @@ func (s *StatsInfo) String() string {_, _ = fmt.Fprintf(buf, "Checks: %10d / %d, %s\n",s.checks, totalChecks, percent(s.checks, totalChecks))}- if s.deletes != 0 {- _, _ = fmt.Fprintf(buf, "Deleted: %10d\n", s.deletes)+ if s.deletes != 0 || s.deletedDirs != 0 {+ _, _ = fmt.Fprintf(buf, "Deleted: %10d (files), %d (dirs)\n", s.deletes, s.deletedDirs)}if s.renames != 0 {_, _ = fmt.Fprintf(buf, "Renamed: %10d\n", s.renames)@@ -459,6 +461,14 @@ func (s *StatsInfo) Deletes(deletes int64) int64 {return s.deletes}+// DeletedDirs updates the stats for deletedDirs+func (s *StatsInfo) DeletedDirs(deletedDirs int64) int64 {+ s.mu.Lock()+ defer s.mu.Unlock()+ s.deletedDirs += deletedDirs+ return s.deletedDirs+}+// Renames updates the stats for renamesfunc (s *StatsInfo) Renames(renames int64) int64 {s.mu.Lock()@@ -480,6 +490,7 @@ func (s *StatsInfo) ResetCounters() {s.checks = 0s.transfers = 0s.deletes = 0+ s.deletedDirs = 0s.renames = 0s.startedTransfers = nils.oldDuration = 0diff --git a/fs/accounting/stats_groups.go b/fs/accounting/stats_groups.goindex 776af484c..c1b2379cc 100644--- a/fs/accounting/stats_groups.go+++ b/fs/accounting/stats_groups.go@@ -358,6 +358,7 @@ func (sg *statsGroups) sum() *StatsInfo {sum.checks += stats.checkssum.transfers += stats.transferssum.deletes += stats.deletes+ sum.deletedDirs += stats.deletedDirssum.renames += stats.renamessum.checking.merge(stats.checking)sum.transferring.merge(stats.transferring)diff --git a/fs/operations/operations.go b/fs/operations/operations.goindex ab8e907f0..64bf6db48 100644--- a/fs/operations/operations.go+++ b/fs/operations/operations.go@@ -935,6 +935,7 @@ func Mkdir(ctx context.Context, f fs.Fs, dir string) error {// TryRmdir removes a container but not if not empty. It doesn't// count errors but may return one.func TryRmdir(ctx context.Context, f fs.Fs, dir string) error {+ accounting.Stats(ctx).DeletedDirs(1)if SkipDestructive(ctx, fs.LogDirName(f, dir), "remove directory") {return nil}@@ -957,6 +958,7 @@ func Purge(ctx context.Context, f fs.Fs, dir string) (err error) {doFallbackPurge := trueif doPurge := f.Features().Purge; doPurge != nil {doFallbackPurge = false+ accounting.Stats(ctx).DeletedDirs(1)if SkipDestructive(ctx, fs.LogDirName(f, dir), "purge directory") {return nil}