From af55a74bd2d2b8b4e8eeac352beb30ed30d2cd56 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 28 Oct 2020 12:54:31 +0000 Subject: [PATCH] stats: add counter for deleted directories - fixes #4676 --- fs/accounting/prometheus.go | 7 +++++++ fs/accounting/stats.go | 15 +++++++++++++-- fs/accounting/stats_groups.go | 1 + fs/operations/operations.go | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/accounting/prometheus.go b/fs/accounting/prometheus.go index e34bc0146..c9d165c95 100644 --- a/fs/accounting/prometheus.go +++ b/fs/accounting/prometheus.go @@ -14,6 +14,7 @@ type RcloneCollector struct { numOfCheckFiles *prometheus.Desc transferredFiles *prometheus.Desc deletes *prometheus.Desc + deletedDirs *prometheus.Desc renames *prometheus.Desc fatalError *prometheus.Desc retryError *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.numOfCheckFiles ch <- c.transferredFiles ch <- c.deletes + ch <- c.deletedDirs ch <- c.renames ch <- c.fatalError ch <- 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.go index 0c5ee2903..1f4992897 100644 --- a/fs/accounting/stats.go +++ b/fs/accounting/stats.go @@ -40,6 +40,7 @@ type StatsInfo struct { renameQueue int renameQueueSize int64 deletes int64 + deletedDirs int64 inProgress *inProgress startedTransfers []*Transfer // currently active transfers oldTimeRanges 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.checks out["transfers"] = s.transfers out["deletes"] = s.deletes + out["deletedDirs"] = s.deletedDirs out["renames"] = s.renames out["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 renames func (s *StatsInfo) Renames(renames int64) int64 { s.mu.Lock() @@ -480,6 +490,7 @@ func (s *StatsInfo) ResetCounters() { s.checks = 0 s.transfers = 0 s.deletes = 0 + s.deletedDirs = 0 s.renames = 0 s.startedTransfers = nil s.oldDuration = 0 diff --git a/fs/accounting/stats_groups.go b/fs/accounting/stats_groups.go index 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.checks sum.transfers += stats.transfers sum.deletes += stats.deletes + sum.deletedDirs += stats.deletedDirs sum.renames += stats.renames sum.checking.merge(stats.checking) sum.transferring.merge(stats.transferring) diff --git a/fs/operations/operations.go b/fs/operations/operations.go index 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 := true if doPurge := f.Features().Purge; doPurge != nil { doFallbackPurge = false + accounting.Stats(ctx).DeletedDirs(1) if SkipDestructive(ctx, fs.LogDirName(f, dir), "purge directory") { return nil }