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-14 02:32:32 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/api"
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/types"
|
2019-10-11 23:47:29 +00:00
|
|
|
lcli "github.com/filecoin-project/go-lotus/cli"
|
2019-10-14 02:32:32 +00:00
|
|
|
sectorstate "github.com/filecoin-project/go-sectorbuilder/sealing_state"
|
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)
|
|
|
|
|
|
|
|
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-10-15 14:51:47 +00:00
|
|
|
fmt.Printf("Power: %s / %s (%0.2f%%)\n", pow.MinerPower, pow.TotalPower, float64(percI.Int64())/1000*100)
|
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-10-14 02:32:32 +00:00
|
|
|
fmt.Println("Sealed Sectors:\t", sinfo.SealedCount)
|
|
|
|
fmt.Println("Sealing Sectors:\t", sinfo.SealingCount)
|
|
|
|
fmt.Println("Pending Sectors:\t", sinfo.PendingCount)
|
|
|
|
fmt.Println("Failed Sectors:\t", sinfo.FailedCount)
|
|
|
|
|
2019-10-11 23:47:29 +00:00
|
|
|
// TODO: grab actr state / info
|
|
|
|
// * Sector size
|
|
|
|
// * Sealed sectors (count / bytes)
|
|
|
|
// * Power
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-10-14 02:32:32 +00:00
|
|
|
|
|
|
|
type SectorsInfo struct {
|
|
|
|
TotalCount int
|
|
|
|
SealingCount int
|
|
|
|
FailedCount int
|
|
|
|
SealedCount int
|
|
|
|
PendingCount int
|
|
|
|
}
|
|
|
|
|
|
|
|
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (*SectorsInfo, error) {
|
|
|
|
sectors, err := napi.SectorsList(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
out := SectorsInfo{
|
|
|
|
TotalCount: len(sectors),
|
|
|
|
}
|
|
|
|
for _, s := range sectors {
|
|
|
|
st, err := napi.SectorsStatus(ctx, s)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch st.State {
|
|
|
|
case sectorstate.Sealed:
|
|
|
|
out.SealedCount++
|
|
|
|
case sectorstate.Pending:
|
|
|
|
out.PendingCount++
|
|
|
|
case sectorstate.Sealing:
|
|
|
|
out.SealingCount++
|
|
|
|
case sectorstate.Failed:
|
|
|
|
out.FailedCount++
|
|
|
|
case sectorstate.Unknown:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &out, nil
|
|
|
|
}
|