2019-08-08 14:47:04 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package storageusage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/storj"
|
2019-08-08 14:47:04 +01:00
|
|
|
)
|
|
|
|
|
2020-12-05 16:01:42 +00:00
|
|
|
// DB works with storage usage database.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2019-08-08 14:47:04 +01:00
|
|
|
type DB interface {
|
|
|
|
// Store stores storage usage stamps to db replacing conflicting entries
|
|
|
|
Store(ctx context.Context, stamps []Stamp) error
|
|
|
|
// GetDaily returns daily storage usage stamps for particular satellite
|
|
|
|
// for provided time range
|
|
|
|
GetDaily(ctx context.Context, satelliteID storj.NodeID, from, to time.Time) ([]Stamp, error)
|
|
|
|
// GetDailyTotal returns daily storage usage stamps summed across all known satellites
|
|
|
|
// for provided time range
|
2023-01-31 12:53:06 +00:00
|
|
|
GetDailyTotal(ctx context.Context, from, to time.Time) ([]StampGroup, error)
|
2019-09-04 15:13:43 +01:00
|
|
|
// Summary returns aggregated storage usage across all satellites.
|
2022-12-05 14:10:04 +00:00
|
|
|
Summary(ctx context.Context, from, to time.Time) (float64, float64, error)
|
2019-09-04 15:13:43 +01:00
|
|
|
// SatelliteSummary returns aggregated storage usage for a particular satellite.
|
2022-12-05 14:10:04 +00:00
|
|
|
SatelliteSummary(ctx context.Context, satelliteID storj.NodeID, from, to time.Time) (float64, float64, error)
|
2019-08-08 14:47:04 +01:00
|
|
|
}
|
|
|
|
|
2019-09-04 15:13:43 +01:00
|
|
|
// Stamp is storage usage stamp for satellite from interval start till next interval.
|
2019-08-08 14:47:04 +01:00
|
|
|
type Stamp struct {
|
2022-07-21 12:15:03 +01:00
|
|
|
SatelliteID storj.NodeID `json:"-"`
|
2022-12-05 14:10:04 +00:00
|
|
|
// AtRestTotal is the bytes*hour disk space used at the IntervalEndTime.
|
2022-11-17 13:31:29 +00:00
|
|
|
AtRestTotal float64 `json:"atRestTotal"`
|
2022-12-05 14:10:04 +00:00
|
|
|
// AtRestTotalBytes is the AtRestTotal divided by the IntervalInHours.
|
|
|
|
AtRestTotalBytes float64 `json:"atRestTotalBytes"`
|
|
|
|
// IntervalInHours is hour difference between interval_end_time
|
|
|
|
// of this Stamp and that of the preceding Stamp
|
|
|
|
IntervalInHours float64 `json:"intervalInHours"`
|
2022-07-21 12:15:03 +01:00
|
|
|
// IntervalStart represents one tally day
|
|
|
|
// TODO: rename to timestamp to match DB
|
|
|
|
IntervalStart time.Time `json:"intervalStart"`
|
|
|
|
// IntervalEndTime represents the timestamp for the last tally run time
|
|
|
|
// (i.e. last interval_end_time) for the day
|
|
|
|
IntervalEndTime time.Time `json:"-"`
|
2019-08-08 14:47:04 +01:00
|
|
|
}
|
2023-01-31 12:53:06 +00:00
|
|
|
|
|
|
|
// StampGroup is storage usage stamp for all satellites from interval start till next interval
|
|
|
|
// grouped by interval_start time.
|
|
|
|
type StampGroup struct {
|
|
|
|
// AtRestTotal is the bytes*hour disk space used at the IntervalEndTime.
|
|
|
|
AtRestTotal float64 `json:"atRestTotal"`
|
|
|
|
// AtRestTotalBytes is the AtRestTotal divided by the IntervalInHours.
|
|
|
|
AtRestTotalBytes float64 `json:"atRestTotalBytes"`
|
|
|
|
// IntervalStart represents one tally day
|
|
|
|
// TODO: rename to timestamp to match DB
|
|
|
|
IntervalStart time.Time `json:"intervalStart"`
|
|
|
|
}
|