Skip to content

Commit b9cf66e

Browse files
committed
Show RPC server status
1 parent 72afa22 commit b9cf66e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

cmd/debug/debug.go

+40
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package debug
22

33
import (
44
"fmt"
5+
"io"
56
"log"
67
"os"
78
"path/filepath"
@@ -11,6 +12,7 @@ import (
1112
"text/tabwriter"
1213

1314
"github.com/chia-network/go-chia-libs/pkg/config"
15+
"github.com/chia-network/go-chia-libs/pkg/rpc"
1416
"github.com/chia-network/go-modules/pkg/slogs"
1517
"github.com/spf13/cobra"
1618
"github.com/spf13/viper"
@@ -53,11 +55,49 @@ var debugCmd = &cobra.Command{
5355
fmt.Println(strings.Repeat("-", 60)) // Separator
5456
debugPorts()
5557

58+
fmt.Println("\n# RPC Server Status")
59+
fmt.Println(strings.Repeat("-", 60)) // Separator
60+
debugRPC()
61+
5662
fmt.Println("\n# File Sizes")
5763
debugFileSizes()
5864
},
5965
}
6066

67+
func debugRPC() {
68+
slogs.Logr.Debug("initializing websocket client")
69+
websocketClient, err := rpc.NewClient(rpc.ConnectionModeWebsocket, rpc.WithAutoConfig(), rpc.WithSyncWebsocket())
70+
if err != nil {
71+
slogs.Logr.Fatal("error initializing websocket RPC client", "error", err)
72+
}
73+
slogs.Logr.Debug("initializing http client")
74+
rpcClient, err := rpc.NewClient(rpc.ConnectionModeHTTP, rpc.WithAutoConfig(), rpc.WithSyncWebsocket())
75+
if err != nil {
76+
slogs.Logr.Fatal("error initializing websocket RPC client", "error", err)
77+
}
78+
79+
w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
80+
runningHelper(w, websocketClient.DaemonService, "Daemon")
81+
runningHelper(w, rpcClient.FullNodeService, "Full Node")
82+
runningHelper(w, rpcClient.WalletService, "Wallet")
83+
runningHelper(w, rpcClient.FarmerService, "Farmer")
84+
runningHelper(w, rpcClient.HarvesterService, "Harvester")
85+
runningHelper(w, rpcClient.CrawlerService, "Crawler")
86+
runningHelper(w, rpcClient.DataLayerService, "Data Layer")
87+
runningHelper(w, rpcClient.TimelordService, "Timelord")
88+
_ = w.Flush()
89+
}
90+
91+
func runningHelper(w io.Writer, service hasVersionInfo, label string) {
92+
running := "Running"
93+
_, _, err := service.GetVersion(&rpc.GetVersionOptions{})
94+
if err != nil {
95+
slogs.Logr.Debug("error getting RPC Status from daemon", "error", err)
96+
running = "Not Running"
97+
}
98+
_, _ = fmt.Fprintln(w, label, "\t", running)
99+
}
100+
61101
func debugPorts() {
62102
cfg, err := config.GetChiaConfig()
63103
if err != nil {

0 commit comments

Comments
 (0)