rcd: Adding group parameter to stats

s3-about
Chaitanya 2019-10-29 15:43:21 +05:30 committed by Nick Craig-Wood
parent 191cfb79d1
commit e0356f5aae
4 changed files with 6 additions and 0 deletions

View File

@ -378,6 +378,7 @@ func (acc *Account) RemoteStats() (out rc.Params) {
percentageDone = int(100 * float64(a) / float64(b))
}
out["percentage"] = percentageDone
out["group"] = acc.stats.group
return out
}

View File

@ -40,6 +40,7 @@ type StatsInfo struct {
startedTransfers []*Transfer // currently active transfers
oldTimeRanges timeRanges // a merged list of time ranges for the transfers
oldDuration time.Duration // duration of transfers we have culled
group string
}
// NewStats creates an initialised StatsInfo

View File

@ -245,6 +245,7 @@ func GlobalStats() *StatsInfo {
// NewStatsGroup creates new stats under named group.
func NewStatsGroup(group string) *StatsInfo {
stats := NewStats()
stats.group = group
groups.set(group, stats)
return stats
}

View File

@ -18,6 +18,7 @@ type TransferSnapshot struct {
StartedAt time.Time `json:"started_at"`
CompletedAt time.Time `json:"completed_at,omitempty"`
Error error `json:"-"`
Group string `json:"group"`
}
// MarshalJSON implements json.Marshaler interface.
@ -26,6 +27,7 @@ func (as TransferSnapshot) MarshalJSON() ([]byte, error) {
if as.Error != nil {
err = as.Error.Error()
}
type Alias TransferSnapshot
return json.Marshal(&struct {
Error string `json:"error"`
@ -176,5 +178,6 @@ func (tr *Transfer) Snapshot() TransferSnapshot {
StartedAt: tr.startedAt,
CompletedAt: tr.completedAt,
Error: tr.err,
Group: tr.stats.group,
}
}