From 40e51baadc6d369d0392d7fc3a83cfe2a0fa3a4c Mon Sep 17 00:00:00 2001 From: Phi Date: Fri, 19 May 2023 14:31:40 +0200 Subject: [PATCH] Add alerts to `Lotus info` cmd Add alerts to `Lotus info` cmd --- cli/info.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cli/info.go b/cli/info.go index 007e3655f..8b36be488 100644 --- a/cli/info.go +++ b/cli/info.go @@ -20,6 +20,7 @@ import ( "github.com/filecoin-project/lotus/api/v1api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/journal/alerting" ) var infoCmd = &cli.Command{ @@ -62,6 +63,21 @@ func infoCmdAct(cctx *cli.Context) error { fmt.Printf(" [epoch %s]\n", color.MagentaString(("%d"), status.SyncStatus.Epoch)) fmt.Printf("Peers to: [publish messages %d] [publish blocks %d]\n", status.PeerStatus.PeersToPublishMsgs, status.PeerStatus.PeersToPublishBlocks) + alerts, err := fullapi.LogAlerts(ctx) + if err != nil { + fmt.Printf("ERROR: getting alerts: %s\n", err) + } + + activeAlerts := make([]alerting.Alert, 0) + for _, alert := range alerts { + if alert.Active { + activeAlerts = append(activeAlerts, alert) + } + } + if len(activeAlerts) > 0 { + fmt.Printf("%s (check %s)\n", color.RedString("⚠ %d Active alerts", len(activeAlerts)), color.YellowString("lotus log alerts")) + } + //Chain health calculated as percentage: amount of blocks in last finality / very healthy amount of blocks in a finality (900 epochs * 5 blocks per tipset) health := (100 * (900 * status.ChainStatus.BlocksPerTipsetLastFinality) / (900 * 5)) switch {