forked from TrueCloudLab/rclone
stats: add counter for deleted directories - fixes #4676
This commit is contained in:
parent
d00c126cef
commit
af55a74bd2
4 changed files with 23 additions and 2 deletions
|
@ -14,6 +14,7 @@ type RcloneCollector struct {
|
||||||
numOfCheckFiles *prometheus.Desc
|
numOfCheckFiles *prometheus.Desc
|
||||||
transferredFiles *prometheus.Desc
|
transferredFiles *prometheus.Desc
|
||||||
deletes *prometheus.Desc
|
deletes *prometheus.Desc
|
||||||
|
deletedDirs *prometheus.Desc
|
||||||
renames *prometheus.Desc
|
renames *prometheus.Desc
|
||||||
fatalError *prometheus.Desc
|
fatalError *prometheus.Desc
|
||||||
retryError *prometheus.Desc
|
retryError *prometheus.Desc
|
||||||
|
@ -46,6 +47,10 @@ func NewRcloneCollector() *RcloneCollector {
|
||||||
"Total number of files deleted",
|
"Total number of files deleted",
|
||||||
nil, nil,
|
nil, nil,
|
||||||
),
|
),
|
||||||
|
deletedDirs: prometheus.NewDesc(namespace+"dirs_deleted_total",
|
||||||
|
"Total number of directories deleted",
|
||||||
|
nil, nil,
|
||||||
|
),
|
||||||
renames: prometheus.NewDesc(namespace+"files_renamed_total",
|
renames: prometheus.NewDesc(namespace+"files_renamed_total",
|
||||||
"Total number of files renamed",
|
"Total number of files renamed",
|
||||||
nil, nil,
|
nil, nil,
|
||||||
|
@ -69,6 +74,7 @@ func (c *RcloneCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- c.numOfCheckFiles
|
ch <- c.numOfCheckFiles
|
||||||
ch <- c.transferredFiles
|
ch <- c.transferredFiles
|
||||||
ch <- c.deletes
|
ch <- c.deletes
|
||||||
|
ch <- c.deletedDirs
|
||||||
ch <- c.renames
|
ch <- c.renames
|
||||||
ch <- c.fatalError
|
ch <- c.fatalError
|
||||||
ch <- c.retryError
|
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.numOfCheckFiles, prometheus.CounterValue, float64(s.checks))
|
||||||
ch <- prometheus.MustNewConstMetric(c.transferredFiles, prometheus.CounterValue, float64(s.transfers))
|
ch <- prometheus.MustNewConstMetric(c.transferredFiles, prometheus.CounterValue, float64(s.transfers))
|
||||||
ch <- prometheus.MustNewConstMetric(c.deletes, prometheus.CounterValue, float64(s.deletes))
|
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.renames, prometheus.CounterValue, float64(s.renames))
|
||||||
ch <- prometheus.MustNewConstMetric(c.fatalError, prometheus.GaugeValue, bool2Float(s.fatalError))
|
ch <- prometheus.MustNewConstMetric(c.fatalError, prometheus.GaugeValue, bool2Float(s.fatalError))
|
||||||
ch <- prometheus.MustNewConstMetric(c.retryError, prometheus.GaugeValue, bool2Float(s.retryError))
|
ch <- prometheus.MustNewConstMetric(c.retryError, prometheus.GaugeValue, bool2Float(s.retryError))
|
||||||
|
|
|
@ -40,6 +40,7 @@ type StatsInfo struct {
|
||||||
renameQueue int
|
renameQueue int
|
||||||
renameQueueSize int64
|
renameQueueSize int64
|
||||||
deletes int64
|
deletes int64
|
||||||
|
deletedDirs int64
|
||||||
inProgress *inProgress
|
inProgress *inProgress
|
||||||
startedTransfers []*Transfer // currently active transfers
|
startedTransfers []*Transfer // currently active transfers
|
||||||
oldTimeRanges timeRanges // a merged list of time ranges for the 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["checks"] = s.checks
|
||||||
out["transfers"] = s.transfers
|
out["transfers"] = s.transfers
|
||||||
out["deletes"] = s.deletes
|
out["deletes"] = s.deletes
|
||||||
|
out["deletedDirs"] = s.deletedDirs
|
||||||
out["renames"] = s.renames
|
out["renames"] = s.renames
|
||||||
out["transferTime"] = s.totalDuration().Seconds()
|
out["transferTime"] = s.totalDuration().Seconds()
|
||||||
out["elapsedTime"] = time.Since(startTime).Seconds()
|
out["elapsedTime"] = time.Since(startTime).Seconds()
|
||||||
|
@ -310,8 +312,8 @@ func (s *StatsInfo) String() string {
|
||||||
_, _ = fmt.Fprintf(buf, "Checks: %10d / %d, %s\n",
|
_, _ = fmt.Fprintf(buf, "Checks: %10d / %d, %s\n",
|
||||||
s.checks, totalChecks, percent(s.checks, totalChecks))
|
s.checks, totalChecks, percent(s.checks, totalChecks))
|
||||||
}
|
}
|
||||||
if s.deletes != 0 {
|
if s.deletes != 0 || s.deletedDirs != 0 {
|
||||||
_, _ = fmt.Fprintf(buf, "Deleted: %10d\n", s.deletes)
|
_, _ = fmt.Fprintf(buf, "Deleted: %10d (files), %d (dirs)\n", s.deletes, s.deletedDirs)
|
||||||
}
|
}
|
||||||
if s.renames != 0 {
|
if s.renames != 0 {
|
||||||
_, _ = fmt.Fprintf(buf, "Renamed: %10d\n", s.renames)
|
_, _ = fmt.Fprintf(buf, "Renamed: %10d\n", s.renames)
|
||||||
|
@ -459,6 +461,14 @@ func (s *StatsInfo) Deletes(deletes int64) int64 {
|
||||||
return s.deletes
|
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
|
// Renames updates the stats for renames
|
||||||
func (s *StatsInfo) Renames(renames int64) int64 {
|
func (s *StatsInfo) Renames(renames int64) int64 {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
|
@ -480,6 +490,7 @@ func (s *StatsInfo) ResetCounters() {
|
||||||
s.checks = 0
|
s.checks = 0
|
||||||
s.transfers = 0
|
s.transfers = 0
|
||||||
s.deletes = 0
|
s.deletes = 0
|
||||||
|
s.deletedDirs = 0
|
||||||
s.renames = 0
|
s.renames = 0
|
||||||
s.startedTransfers = nil
|
s.startedTransfers = nil
|
||||||
s.oldDuration = 0
|
s.oldDuration = 0
|
||||||
|
|
|
@ -358,6 +358,7 @@ func (sg *statsGroups) sum() *StatsInfo {
|
||||||
sum.checks += stats.checks
|
sum.checks += stats.checks
|
||||||
sum.transfers += stats.transfers
|
sum.transfers += stats.transfers
|
||||||
sum.deletes += stats.deletes
|
sum.deletes += stats.deletes
|
||||||
|
sum.deletedDirs += stats.deletedDirs
|
||||||
sum.renames += stats.renames
|
sum.renames += stats.renames
|
||||||
sum.checking.merge(stats.checking)
|
sum.checking.merge(stats.checking)
|
||||||
sum.transferring.merge(stats.transferring)
|
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
|
// TryRmdir removes a container but not if not empty. It doesn't
|
||||||
// count errors but may return one.
|
// count errors but may return one.
|
||||||
func TryRmdir(ctx context.Context, f fs.Fs, dir string) error {
|
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") {
|
if SkipDestructive(ctx, fs.LogDirName(f, dir), "remove directory") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -957,6 +958,7 @@ func Purge(ctx context.Context, f fs.Fs, dir string) (err error) {
|
||||||
doFallbackPurge := true
|
doFallbackPurge := true
|
||||||
if doPurge := f.Features().Purge; doPurge != nil {
|
if doPurge := f.Features().Purge; doPurge != nil {
|
||||||
doFallbackPurge = false
|
doFallbackPurge = false
|
||||||
|
accounting.Stats(ctx).DeletedDirs(1)
|
||||||
if SkipDestructive(ctx, fs.LogDirName(f, dir), "purge directory") {
|
if SkipDestructive(ctx, fs.LogDirName(f, dir), "purge directory") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue