fs: add renames statistic for file and directory renames
This commit is contained in:
parent
ad9c7ff7ed
commit
b5f1bebc52
4 changed files with 32 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
|
||||||
|
renames *prometheus.Desc
|
||||||
fatalError *prometheus.Desc
|
fatalError *prometheus.Desc
|
||||||
retryError *prometheus.Desc
|
retryError *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
@ -45,6 +46,10 @@ func NewRcloneCollector() *RcloneCollector {
|
||||||
"Total number of files deleted",
|
"Total number of files deleted",
|
||||||
nil, nil,
|
nil, nil,
|
||||||
),
|
),
|
||||||
|
renames: prometheus.NewDesc(namespace+"files_renamed_total",
|
||||||
|
"Total number of files renamed",
|
||||||
|
nil, nil,
|
||||||
|
),
|
||||||
fatalError: prometheus.NewDesc(namespace+"fatal_error",
|
fatalError: prometheus.NewDesc(namespace+"fatal_error",
|
||||||
"Whether a fatal error has occurred",
|
"Whether a fatal error has occurred",
|
||||||
nil, nil,
|
nil, nil,
|
||||||
|
@ -64,6 +69,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.renames
|
||||||
ch <- c.fatalError
|
ch <- c.fatalError
|
||||||
ch <- c.retryError
|
ch <- c.retryError
|
||||||
}
|
}
|
||||||
|
@ -79,6 +85,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.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))
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ type StatsInfo struct {
|
||||||
transferring *stringSet
|
transferring *stringSet
|
||||||
transferQueue int
|
transferQueue int
|
||||||
transferQueueSize int64
|
transferQueueSize int64
|
||||||
|
renames int64
|
||||||
renameQueue int
|
renameQueue int
|
||||||
renameQueueSize int64
|
renameQueueSize int64
|
||||||
deletes int64
|
deletes int64
|
||||||
|
@ -64,6 +65,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["renames"] = s.renames
|
||||||
out["elapsedTime"] = s.totalDuration().Seconds()
|
out["elapsedTime"] = s.totalDuration().Seconds()
|
||||||
s.mu.RUnlock()
|
s.mu.RUnlock()
|
||||||
if !s.checking.empty() {
|
if !s.checking.empty() {
|
||||||
|
@ -330,6 +332,9 @@ func (s *StatsInfo) String() string {
|
||||||
if s.deletes != 0 {
|
if s.deletes != 0 {
|
||||||
_, _ = fmt.Fprintf(buf, "Deleted: %10d\n", s.deletes)
|
_, _ = fmt.Fprintf(buf, "Deleted: %10d\n", s.deletes)
|
||||||
}
|
}
|
||||||
|
if s.renames != 0 {
|
||||||
|
_, _ = fmt.Fprintf(buf, "Renamed: %10d\n", s.renames)
|
||||||
|
}
|
||||||
if s.transfers != 0 || totalTransfer != 0 {
|
if s.transfers != 0 || totalTransfer != 0 {
|
||||||
_, _ = fmt.Fprintf(buf, "Transferred: %10d / %d, %s\n",
|
_, _ = fmt.Fprintf(buf, "Transferred: %10d / %d, %s\n",
|
||||||
s.transfers, totalTransfer, percent(s.transfers, totalTransfer))
|
s.transfers, totalTransfer, percent(s.transfers, totalTransfer))
|
||||||
|
@ -467,7 +472,15 @@ func (s *StatsInfo) Deletes(deletes int64) int64 {
|
||||||
return s.deletes
|
return s.deletes
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetCounters sets the counters (bytes, checks, errors, transfers, deletes) to 0 and resets lastError, fatalError and retryError
|
// Renames updates the stats for renames
|
||||||
|
func (s *StatsInfo) Renames(renames int64) int64 {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
s.renames += renames
|
||||||
|
return s.renames
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetCounters sets the counters (bytes, checks, errors, transfers, deletes, renames) to 0 and resets lastError, fatalError and retryError
|
||||||
func (s *StatsInfo) ResetCounters() {
|
func (s *StatsInfo) ResetCounters() {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
@ -480,6 +493,7 @@ func (s *StatsInfo) ResetCounters() {
|
||||||
s.checks = 0
|
s.checks = 0
|
||||||
s.transfers = 0
|
s.transfers = 0
|
||||||
s.deletes = 0
|
s.deletes = 0
|
||||||
|
s.renames = 0
|
||||||
s.startedTransfers = nil
|
s.startedTransfers = nil
|
||||||
s.oldDuration = 0
|
s.oldDuration = 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ Returns the following values:
|
||||||
"checks": number of checked files,
|
"checks": number of checked files,
|
||||||
"transfers": number of transferred files,
|
"transfers": number of transferred files,
|
||||||
"deletes" : number of deleted files,
|
"deletes" : number of deleted files,
|
||||||
|
"renames" : number of renamed files,
|
||||||
"elapsedTime": time in seconds since the start of the process,
|
"elapsedTime": time in seconds since the start of the process,
|
||||||
"lastError": last occurred error,
|
"lastError": last occurred error,
|
||||||
"transferring": an array of currently active file transfers:
|
"transferring": an array of currently active file transfers:
|
||||||
|
@ -356,6 +357,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.renames += stats.renames
|
||||||
sum.checking.merge(stats.checking)
|
sum.checking.merge(stats.checking)
|
||||||
sum.transferring.merge(stats.transferring)
|
sum.transferring.merge(stats.transferring)
|
||||||
sum.inProgress.merge(stats.inProgress)
|
sum.inProgress.merge(stats.inProgress)
|
||||||
|
|
|
@ -513,6 +513,9 @@ func SameObject(src, dst fs.Object) bool {
|
||||||
func Move(ctx context.Context, fdst fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Object, err error) {
|
func Move(ctx context.Context, fdst fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Object, err error) {
|
||||||
tr := accounting.Stats(ctx).NewCheckingTransfer(src)
|
tr := accounting.Stats(ctx).NewCheckingTransfer(src)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
accounting.Stats(ctx).Renames(1)
|
||||||
|
}
|
||||||
tr.Done(err)
|
tr.Done(err)
|
||||||
}()
|
}()
|
||||||
newDst = dst
|
newDst = dst
|
||||||
|
@ -2058,7 +2061,11 @@ func (l *ListFormat) Format(entry *ListJSONItem) (result string) {
|
||||||
func DirMove(ctx context.Context, f fs.Fs, srcRemote, dstRemote string) (err error) {
|
func DirMove(ctx context.Context, f fs.Fs, srcRemote, dstRemote string) (err error) {
|
||||||
// Use DirMove if possible
|
// Use DirMove if possible
|
||||||
if doDirMove := f.Features().DirMove; doDirMove != nil {
|
if doDirMove := f.Features().DirMove; doDirMove != nil {
|
||||||
return doDirMove(ctx, f, srcRemote, dstRemote)
|
err = doDirMove(ctx, f, srcRemote, dstRemote)
|
||||||
|
if err == nil {
|
||||||
|
accounting.Stats(ctx).Renames(1)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the directory tree into memory
|
// Load the directory tree into memory
|
||||||
|
|
Loading…
Add table
Reference in a new issue