diff --git a/docs/content/rc.md b/docs/content/rc.md index aef592180..87f09f4b9 100644 --- a/docs/content/rc.md +++ b/docs/content/rc.md @@ -396,7 +396,7 @@ This tells the go runtime to do a garbage collection run. It isn't necessary to call this normally, but it can be useful for debugging memory problems. -### core/group_list: Returns list of stats. +### core/group-list: Returns list of stats. This returns list of stats groups currently in memory. @@ -481,6 +481,14 @@ Returns the following values: Values for "transferring", "checking" and "lastError" are only assigned if data is available. The value for "eta" is null if an eta cannot be determined. +### core/stats-reset: Reset stats. + +This clears counters and errors for all stats or specific stats group if group +is provided. + +Parameters +- group - name of the stats group (string) + ### core/transferred: Returns stats about completed transfers. This returns stats about completed transfers: diff --git a/fs/accounting/stats_groups.go b/fs/accounting/stats_groups.go index 5376af69d..880cf4500 100644 --- a/fs/accounting/stats_groups.go +++ b/fs/accounting/stats_groups.go @@ -51,6 +51,23 @@ func transferredStats(ctx context.Context, in rc.Params) (rc.Params, error) { return out, nil } +func resetStats(ctx context.Context, in rc.Params) (rc.Params, error) { + // Check to see if we should filter by group. + group, err := in.GetString("group") + if rc.NotErrParamNotFound(err) { + return rc.Params{}, err + } + + if group != "" { + groups.get(group).ResetCounters() + groups.get(group).ResetErrors() + } else { + groups.clear() + } + + return rc.Params{}, nil +} + func init() { // Init stats container groups = newStatsGroups() @@ -143,7 +160,7 @@ Returns the following values: }) rc.Add(rc.Call{ - Path: "core/group_list", + Path: "core/group-list", Fn: listStats, Title: "Returns list of stats.", Help: ` @@ -159,6 +176,19 @@ Returns the following values: ... ] } +`, + }) + + rc.Add(rc.Call{ + Path: "core/stats-reset", + Fn: resetStats, + Title: "Reset stats.", + Help: ` +This clears counters and errors for all stats or specific stats group if group +is provided. + +Parameters +- group - name of the stats group (string) `, }) } @@ -287,3 +317,16 @@ func (sg *statsGroups) sum() *StatsInfo { } return sum } + +func (sg *statsGroups) clear() { + sg.mu.Lock() + defer sg.mu.Unlock() + + for _, stats := range sg.m { + stats.ResetErrors() + stats.ResetCounters() + } + + sg.m = make(map[string]*StatsInfo) + sg.order = nil +} diff --git a/fs/rc/jobs/job.go b/fs/rc/jobs/job.go index c43ca7d6c..887b7d805 100644 --- a/fs/rc/jobs/job.go +++ b/fs/rc/jobs/job.go @@ -5,6 +5,7 @@ package jobs import ( "context" "fmt" + "runtime/debug" "sync" "sync/atomic" "time" @@ -126,7 +127,7 @@ func (job *Job) finish(out rc.Params, err error) { func (job *Job) run(ctx context.Context, fn rc.Func, in rc.Params) { defer func() { if r := recover(); r != nil { - job.finish(nil, errors.Errorf("panic received: %v", r)) + job.finish(nil, errors.Errorf("panic received: %v \n%s", r, string(debug.Stack()))) } }() job.finish(fn(ctx, in)) diff --git a/fs/rc/jobs/job_test.go b/fs/rc/jobs/job_test.go index 227230d98..99b779432 100644 --- a/fs/rc/jobs/job_test.go +++ b/fs/rc/jobs/job_test.go @@ -184,7 +184,7 @@ func TestJobRunPanic(t *testing.T) { assert.Equal(t, false, job.EndTime.IsZero()) assert.Equal(t, rc.Params{}, job.Output) assert.True(t, job.Duration >= floatSleepTime) - assert.Equal(t, "panic received: boom", job.Error) + assert.Contains(t, job.Error, "panic received: boom") assert.Equal(t, false, job.Success) assert.Equal(t, true, job.Finished) job.mu.Unlock()