Fix Dashboard calculation for used space and bandwidth usage (#1615)
* Fix Dashboard calculation for used space and bandwidth usage * Copy+Paste Err
This commit is contained in:
parent
872bd5d7c1
commit
c50a21d4cf
@ -55,10 +55,19 @@ func NewEndpoint(log *zap.Logger, pieceInfo pieces.DB, kademlia *kademlia.Kademl
|
||||
}
|
||||
|
||||
func (inspector *Endpoint) retrieveStats(ctx context.Context) (*pb.StatSummaryResponse, error) {
|
||||
|
||||
// Space Usage
|
||||
totalUsedSpace, err := inspector.pieceInfo.SpaceUsed(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
totalUsedSpaceOld, err := inspector.psdbDB.SumTTLSizes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
totalUsedSpace += totalUsedSpaceOld
|
||||
|
||||
// Bandwidth Usage
|
||||
usage, err := inspector.usageDB.Summary(ctx, getBeginningOfMonth(), time.Now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -67,7 +76,7 @@ func (inspector *Endpoint) retrieveStats(ctx context.Context) (*pb.StatSummaryRe
|
||||
egress := usage.Get + usage.GetAudit + usage.GetRepair
|
||||
|
||||
totalUsedBandwidth := int64(0)
|
||||
oldUsage, err := inspector.psdbDB.SumTTLSizes()
|
||||
oldUsage, err := inspector.psdbDB.GetTotalBandwidthBetween(getBeginningOfMonth(), time.Now())
|
||||
if err != nil {
|
||||
inspector.log.Warn("unable to calculate old bandwidth usage")
|
||||
} else {
|
||||
@ -78,11 +87,11 @@ func (inspector *Endpoint) retrieveStats(ctx context.Context) (*pb.StatSummaryRe
|
||||
|
||||
return &pb.StatSummaryResponse{
|
||||
UsedSpace: totalUsedSpace,
|
||||
AvailableSpace: (inspector.config.AllocatedDiskSpace.Int64() - totalUsedSpace),
|
||||
AvailableSpace: inspector.config.AllocatedDiskSpace.Int64() - totalUsedSpace,
|
||||
UsedIngress: ingress,
|
||||
UsedEgress: egress,
|
||||
UsedBandwidth: totalUsedBandwidth,
|
||||
AvailableBandwidth: (inspector.config.AllocatedBandwidth.Int64() - totalUsedBandwidth),
|
||||
AvailableBandwidth: inspector.config.AllocatedBandwidth.Int64() - totalUsedBandwidth,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user