mirror of
https://github.com/rclone/rclone.git
synced 2025-12-16 00:04:40 +00:00
accounting: change stats interface
This is done to make clear ownership over accounting object and prepare for removing global stats object. Stats elapsed time calculation has been altered to account for actual transfer time instead of stats creation time.
This commit is contained in:
committed by
Nick Craig-Wood
parent
2d561b51db
commit
be0464f5f1
@@ -75,8 +75,8 @@ func Error(what interface{}, w http.ResponseWriter, text string, err error) {
|
||||
// Serve serves a directory
|
||||
func (d *Directory) Serve(w http.ResponseWriter, r *http.Request) {
|
||||
// Account the transfer
|
||||
accounting.Stats.Transferring(d.DirRemote)
|
||||
defer accounting.Stats.DoneTransferring(d.DirRemote, true)
|
||||
tr := accounting.Stats.NewTransferRemoteSize(d.DirRemote, -1)
|
||||
defer tr.Done(nil)
|
||||
|
||||
fs.Infof(d.DirRemote, "%s: Serving directory", r.RemoteAddr)
|
||||
|
||||
|
||||
@@ -75,22 +75,11 @@ func Object(w http.ResponseWriter, r *http.Request, o fs.Object) {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
accounting.Stats.Transferring(o.Remote())
|
||||
in := accounting.NewAccount(file, o) // account the transfer (no buffering)
|
||||
tr := accounting.Stats.NewTransfer(o)
|
||||
defer func() {
|
||||
closeErr := in.Close()
|
||||
if closeErr != nil {
|
||||
fs.Errorf(o, "Get request: close failed: %v", closeErr)
|
||||
if err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
}
|
||||
ok := err == nil
|
||||
accounting.Stats.DoneTransferring(o.Remote(), ok)
|
||||
if !ok {
|
||||
accounting.Stats.Error(err)
|
||||
}
|
||||
tr.Done(err)
|
||||
}()
|
||||
in := tr.Account(file) // account the transfer (no buffering)
|
||||
|
||||
w.WriteHeader(code)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user