rcd: Adding group parameter to stats

This commit is contained in:
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)) percentageDone = int(100 * float64(a) / float64(b))
} }
out["percentage"] = percentageDone out["percentage"] = percentageDone
out["group"] = acc.stats.group
return out return out
} }

View File

@ -40,6 +40,7 @@ type StatsInfo struct {
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
oldDuration time.Duration // duration of transfers we have culled oldDuration time.Duration // duration of transfers we have culled
group string
} }
// NewStats creates an initialised StatsInfo // NewStats creates an initialised StatsInfo

View File

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

View File

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