informer/disk: set repoSize weight to negative
smaller repositories should have more priority
This commit is contained in:
parent
f7e62beee2
commit
e8695dc6f3
|
@ -105,7 +105,8 @@ func (disk *Informer) GetMetrics(ctx context.Context) []api.Metric {
|
|||
}
|
||||
|
||||
var repoStat api.IPFSRepoStat
|
||||
var metric uint64
|
||||
var weight uint64
|
||||
var value string
|
||||
|
||||
valid := true
|
||||
|
||||
|
@ -126,24 +127,27 @@ func (disk *Informer) GetMetrics(ctx context.Context) []api.Metric {
|
|||
size := repoStat.RepoSize
|
||||
total := repoStat.StorageMax
|
||||
if size < total {
|
||||
metric = total - size
|
||||
weight = total - size
|
||||
} else {
|
||||
// Make sure we don't underflow and stop
|
||||
// sending this metric when space is exhausted.
|
||||
metric = 0
|
||||
weight = 0
|
||||
valid = false
|
||||
logger.Warn("reported freespace is 0")
|
||||
}
|
||||
value = fmt.Sprintf("%d", weight)
|
||||
case MetricRepoSize:
|
||||
metric = repoStat.RepoSize
|
||||
// smaller repositories have more priority
|
||||
weight = -repoStat.RepoSize
|
||||
value = fmt.Sprintf("%d", repoStat.RepoSize)
|
||||
}
|
||||
}
|
||||
|
||||
m := api.Metric{
|
||||
Name: disk.Name(),
|
||||
Value: fmt.Sprintf("%d", metric),
|
||||
Value: value,
|
||||
Valid: valid,
|
||||
Weight: int64(metric),
|
||||
Weight: int64(weight),
|
||||
Partitionable: false,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user