Merge pull request #1725 from ipfs-cluster/metrics-freespace

Metrics freespace
This commit is contained in:
Hector Sanjuan 2022-06-23 14:19:00 +02:00 committed by GitHub
commit 3e6577c22a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -8,10 +8,12 @@ import (
"sync"
"github.com/ipfs-cluster/ipfs-cluster/api"
"github.com/ipfs-cluster/ipfs-cluster/observations"
logging "github.com/ipfs/go-log/v2"
rpc "github.com/libp2p/go-libp2p-gorpc"
"go.opencensus.io/stats"
"go.opencensus.io/trace"
)
@ -105,7 +107,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,27 +129,33 @@ 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,
}
m.SetTTL(disk.config.MetricTTL)
stats.Record(ctx, observations.InformerDisk.M(m.Weight))
return []api.Metric{m}
}

View File

@ -44,10 +44,12 @@ var (
PinsPinAdd = stats.Int64("pins/pin_add", "Total number of IPFS pin requests", stats.UnitDimensionless)
PinsPinAddError = stats.Int64("pins/pin_add_errors", "Total number of failed pin requests", stats.UnitDimensionless)
BlocksPut = stats.Int64("blocks/put", "Total number of blocks/put requests", stats.UnitDimensionless)
BlocksAddedSize = stats.Int64("blocks/added_size", "Total size of blocks added in bytes", stats.UnitDimensionless)
BlocksAddedSize = stats.Int64("blocks/added_size", "Total size of blocks added in bytes", stats.UnitBytes)
BlocksAdded = stats.Int64("blocks/added", "Total number of blocks added", stats.UnitDimensionless)
BlocksAddedError = stats.Int64("blocks/put_errors", "Total number of block/put errors", stats.UnitDimensionless)
InformerDisk = stats.Int64("informer/disk", "The metric value weight issued by disk informer", stats.UnitDimensionless)
)
// views, which is just the aggregation of the metrics
@ -114,6 +116,11 @@ var (
Aggregation: view.Sum(),
}
InformerDiskView = &view.View{
Measure: InformerDisk,
Aggregation: view.LastValue(),
}
DefaultViews = []*view.View{
PinsView,
PinsQueuedView,
@ -126,6 +133,7 @@ var (
BlocksAddedSizeView,
BlocksAddedView,
BlocksAddedErrorView,
InformerDiskView,
}
)