mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 17:14:44 +01:00
stats: add counter for deleted directories - fixes #4676
This commit is contained in:
parent
d00c126cef
commit
af55a74bd2
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user