lotus/cmd/lotus-storage-miner/workers.go

83 lines
2.0 KiB
Go
Raw Normal View History

2020-03-23 12:29:24 +00:00
package main
2020-03-23 14:56:22 +00:00
import (
"fmt"
"github.com/filecoin-project/lotus/chain/types"
2020-04-23 22:23:20 +00:00
"github.com/filecoin-project/sector-storage/storiface"
2020-03-23 14:56:22 +00:00
"gopkg.in/urfave/cli.v2"
"sort"
lcli "github.com/filecoin-project/lotus/cli"
)
var workersCmd = &cli.Command{
Name: "workers",
Usage: "interact with workers",
Subcommands: []*cli.Command{
workersListCmd,
},
}
var workersListCmd = &cli.Command{
Name: "list",
Usage: "list workers",
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
stats, err := nodeApi.WorkerStats(ctx)
if err != nil {
return err
}
2020-03-24 23:49:45 +00:00
type sortableStat struct {
id uint64
2020-04-23 22:23:20 +00:00
storiface.WorkerStats
2020-03-24 23:49:45 +00:00
}
st := make([]sortableStat, 0, len(stats))
2020-03-23 14:56:22 +00:00
for id, stat := range stats {
2020-03-24 23:49:45 +00:00
st = append(st, sortableStat{id, stat})
2020-03-23 14:56:22 +00:00
}
sort.Slice(st, func(i, j int) bool {
return st[i].id < st[j].id
})
for _, stat := range st {
gpuUse := "not "
if stat.GpuUsed {
gpuUse = ""
}
fmt.Printf("Worker %d, host %s\n", stat.id, stat.Info.Hostname)
fmt.Printf("\tCPU: %d core(s) in use\n", stat.CpuUse)
2020-03-23 14:56:22 +00:00
for _, gpu := range stat.Info.Resources.GPUs {
fmt.Printf("\tGPU: %s, %sused\n", gpu, gpuUse)
}
fmt.Printf("\tMemory: System: Physical %s, Swap %s, Reserved %s (%d%% phys)\n",
types.SizeStr(types.NewInt(stat.Info.Resources.MemPhysical)),
types.SizeStr(types.NewInt(stat.Info.Resources.MemSwap)),
types.SizeStr(types.NewInt(stat.Info.Resources.MemReserved)),
stat.Info.Resources.MemReserved*100/stat.Info.Resources.MemPhysical)
2020-03-23 14:56:22 +00:00
fmt.Printf("\t\tUsed: Physical %s (%d%% phys), Virtual %s (%d%% phys, %d%% virt)\n",
types.SizeStr(types.NewInt(stat.MemUsedMin)),
stat.MemUsedMin*100/stat.Info.Resources.MemPhysical,
2020-03-23 14:56:22 +00:00
types.SizeStr(types.NewInt(stat.MemUsedMax)),
stat.MemUsedMax*100/stat.Info.Resources.MemPhysical,
stat.MemUsedMax*100/(stat.Info.Resources.MemPhysical+stat.Info.Resources.MemSwap))
2020-03-23 14:56:22 +00:00
}
return nil
},
}