diff --git a/api/api_storage.go b/api/api_storage.go index 9f032ecb2..d8c33f4f7 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -113,6 +113,8 @@ type StorageMiner interface { // WorkerConnect tells the node to connect to workers RPC WorkerConnect(context.Context, string) error + WorkerStats(context.Context) (map[uint64]WorkerStats, error) + stores.SectorIndex MarketImportDealData(ctx context.Context, propcid cid.Cid, path string) error diff --git a/api/api_worker.go b/api/api_worker.go index 999120643..113952adb 100644 --- a/api/api_worker.go +++ b/api/api_worker.go @@ -35,3 +35,12 @@ type WorkerInfo struct { Resources WorkerResources } + +type WorkerStats struct { + Info WorkerInfo + + MemUsedMin uint64 + MemUsedMax uint64 + GpuUsed bool + CpuUse int +} diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index b1a6b265e..0a2c297b7 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -182,6 +182,8 @@ type StorageMinerStruct struct { SectorsUpdate func(context.Context, abi.SectorNumber, api.SectorState) error `perm:"write"` WorkerConnect func(context.Context, string) error `perm:"admin"` // TODO: worker perm + WorkerStats func(context.Context) (map[uint64]api.WorkerStats, error) `perm:"admin"` + StorageList func(context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"` StorageLocal func(context.Context) (map[stores.ID]string, error) `perm:"admin"` StorageAttach func(context.Context, stores.StorageInfo, stores.FsStat) error `perm:"admin"` @@ -658,6 +660,10 @@ func (c *StorageMinerStruct) WorkerConnect(ctx context.Context, url string) erro return c.Internal.WorkerConnect(ctx, url) } +func (c *StorageMinerStruct) WorkerStats(ctx context.Context) (map[uint64]api.WorkerStats, error) { + return c.Internal.WorkerStats(ctx) +} + func (c *StorageMinerStruct) StorageAttach(ctx context.Context, si stores.StorageInfo, st stores.FsStat) error { return c.Internal.StorageAttach(ctx, si, st) } diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index f0480de89..2ed147531 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -30,6 +30,7 @@ func main() { sectorsCmd, storageCmd, setPriceCmd, + workersCmd, } jaeger := tracing.SetupJaegerTracing("lotus") defer func() { diff --git a/cmd/lotus-storage-miner/storage.go b/cmd/lotus-storage-miner/storage.go index 417c5b83a..397894edf 100644 --- a/cmd/lotus-storage-miner/storage.go +++ b/cmd/lotus-storage-miner/storage.go @@ -134,9 +134,19 @@ var storageListCmd = &cli.Command{ return err } - for id, sectors := range st { + sorted := make([]struct{stores.ID; sectors []stores.Decl}, 0, len(st)) + for id, decls := range st { + sorted = append(sorted, struct{stores.ID; sectors []stores.Decl}{id, decls}) + } + + sort.Slice(sorted, func(i, j int) bool { + return sorted[i].ID < sorted[j].ID + }) + + for _, s := range sorted { + var cnt [3]int - for _, decl := range sectors { + for _, decl := range s.sectors { for i := range cnt { if decl.SectorFileType&(1<