2019-10-11 23:47:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-14 02:32:32 +00:00
|
|
|
"context"
|
2019-10-11 23:47:29 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2019-11-09 09:49:43 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2019-10-11 23:47:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var infoCmd = &cli.Command{
|
|
|
|
Name: "info",
|
|
|
|
Usage: "Print storage miner info",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
2019-10-14 02:32:32 +00:00
|
|
|
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
2019-10-11 23:47:29 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2019-10-14 02:32:32 +00:00
|
|
|
maddr, err := nodeApi.ActorAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Miner: %s\n", maddr)
|
|
|
|
|
2019-11-07 10:46:11 +00:00
|
|
|
// Sector size
|
2019-11-07 12:05:03 +00:00
|
|
|
sizeByte, err := api.StateMinerSectorSize(ctx, maddr, nil)
|
2019-11-07 10:46:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-07 12:05:03 +00:00
|
|
|
|
2019-11-13 14:48:57 +00:00
|
|
|
fmt.Printf("Sector Size: %s\n", sizeStr(types.NewInt(sizeByte)))
|
2019-11-07 10:46:11 +00:00
|
|
|
|
2019-10-14 02:32:32 +00:00
|
|
|
pow, err := api.StateMinerPower(ctx, maddr, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower)
|
2019-11-13 14:48:57 +00:00
|
|
|
fmt.Printf("Power: %s / %s (%0.4f%%)\n", sizeStr(pow.MinerPower), sizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000)
|
2019-10-14 02:32:32 +00:00
|
|
|
|
2019-11-08 18:15:13 +00:00
|
|
|
// TODO: indicate whether the post worker is in use
|
|
|
|
wstat, err := nodeApi.WorkerStats(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-09 09:02:55 +00:00
|
|
|
fmt.Printf("Worker use: %d / %d (+%d)\n", wstat.Total-wstat.Reserved-wstat.Free, wstat.Total, wstat.Reserved)
|
2019-11-08 18:15:13 +00:00
|
|
|
|
2019-11-09 09:49:43 +00:00
|
|
|
ppe, err := api.StateMinerProvingPeriodEnd(ctx, maddr, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-09 12:11:46 +00:00
|
|
|
if ppe != 0 {
|
|
|
|
head, err := api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pdiff := int64(ppe - head.Height())
|
|
|
|
pdifft := pdiff * build.BlockDelay
|
|
|
|
fmt.Printf("Proving Period: %d, in %d Blocks (~%dm %ds)\n", ppe, pdiff, pdifft/60, pdifft%60)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Proving Period: Not Proving\n")
|
2019-11-09 09:49:43 +00:00
|
|
|
}
|
2019-11-09 12:11:46 +00:00
|
|
|
|
2019-10-14 02:32:32 +00:00
|
|
|
sinfo, err := sectorsInfo(ctx, nodeApi)
|
2019-10-11 23:47:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-09 09:49:43 +00:00
|
|
|
fmt.Println("Sectors: ", sinfo)
|
2019-10-14 02:32:32 +00:00
|
|
|
|
2019-10-11 23:47:29 +00:00
|
|
|
// TODO: grab actr state / info
|
|
|
|
// * Sealed sectors (count / bytes)
|
|
|
|
// * Power
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-10-14 02:32:32 +00:00
|
|
|
|
2019-11-13 14:48:57 +00:00
|
|
|
var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}
|
2019-11-07 12:05:03 +00:00
|
|
|
|
2019-11-13 14:48:57 +00:00
|
|
|
func sizeStr(size types.BigInt) string {
|
|
|
|
size = types.BigMul(size, types.NewInt(100))
|
2019-11-07 12:05:03 +00:00
|
|
|
i := 0
|
2019-11-13 14:48:57 +00:00
|
|
|
for types.BigCmp(size, types.NewInt(102400)) >= 0 && i < len(Units)-1 {
|
|
|
|
size = types.BigDiv(size, types.NewInt(1024))
|
2019-11-07 12:05:03 +00:00
|
|
|
i++
|
|
|
|
}
|
2019-11-13 14:48:57 +00:00
|
|
|
return fmt.Sprintf("%s.%s %s", types.BigDiv(size, types.NewInt(100)), types.BigMod(size, types.NewInt(100)), Units[i])
|
2019-11-07 12:05:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-01 03:57:10 +00:00
|
|
|
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
|
2019-10-14 02:32:32 +00:00
|
|
|
sectors, err := napi.SectorsList(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-01 03:57:10 +00:00
|
|
|
out := map[string]int{
|
|
|
|
"Total": len(sectors),
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
for _, s := range sectors {
|
|
|
|
st, err := napi.SectorsStatus(ctx, s)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-08 18:15:13 +00:00
|
|
|
out[api.SectorStateStr(st.State)]++
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
2019-11-01 03:57:10 +00:00
|
|
|
return out, nil
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|