diff options
author | Wolfy-J <[email protected]> | 2018-06-10 19:33:00 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-10 19:33:00 +0300 |
commit | ade5cc504e2b082d0838cc93c3a185246fdc7834 (patch) | |
tree | 5625fb06ff16209b76263a1acbe857c141ba5eba /cmd/rr | |
parent | cb3e7a6b4ec294e7c44c0752f88ffea2297d58b9 (diff) |
nicer worker list
Diffstat (limited to 'cmd/rr')
-rw-r--r-- | cmd/rr/http/reset.go | 5 | ||||
-rw-r--r-- | cmd/rr/http/workers.go | 54 |
2 files changed, 51 insertions, 8 deletions
diff --git a/cmd/rr/http/reset.go b/cmd/rr/http/reset.go index f5c100cc..2583f8cd 100644 --- a/cmd/rr/http/reset.go +++ b/cmd/rr/http/reset.go @@ -26,6 +26,7 @@ import ( rr "github.com/spiral/roadrunner/cmd/rr/cmd" "github.com/spiral/roadrunner/rpc" "github.com/spiral/roadrunner/service" + "github.com/spiral/roadrunner/cmd/rr/utils" ) func init() { @@ -48,11 +49,13 @@ func reloadHandler(cmd *cobra.Command, args []string) error { } defer client.Close() + utils.Printf("<green>restarting http worker pool</reset>: ") + var r string if err := client.Call("http.Reset", true, &r); err != nil { return err } - rr.Logger.Info("http: restarting worker pool") + utils.Printf("<green+hb>done</reset>") return nil } diff --git a/cmd/rr/http/workers.go b/cmd/rr/http/workers.go index 9ad20be7..b5da833d 100644 --- a/cmd/rr/http/workers.go +++ b/cmd/rr/http/workers.go @@ -24,7 +24,7 @@ import ( "errors" "github.com/spf13/cobra" rr "github.com/spiral/roadrunner/cmd/rr/cmd" - "github.com/spiral/roadrunner/rpc" + rrpc "github.com/spiral/roadrunner/rpc" "github.com/spiral/roadrunner/service" "github.com/spiral/roadrunner/http" "github.com/olekukonko/tablewriter" @@ -34,28 +34,65 @@ import ( "github.com/dustin/go-humanize" "github.com/spiral/roadrunner/cmd/rr/utils" "github.com/shirou/gopsutil/process" + "net/rpc" + tm "github.com/buger/goterm" +) + +var ( + interactive bool + stopSignal = make(chan os.Signal, 1) ) func init() { - rr.CLI.AddCommand(&cobra.Command{ + workersCommand := &cobra.Command{ Use: "http:workers", Short: "List workers associated with RoadRunner HTTP service", RunE: workersHandler, - }) + } + + workersCommand.Flags().BoolVarP( + &interactive, + "interactive", + "i", + false, + "render interactive workers table", + ) + + rr.CLI.AddCommand(workersCommand) } func workersHandler(cmd *cobra.Command, args []string) error { - svc, st := rr.Container.Get(rpc.Name) + svc, st := rr.Container.Get(rrpc.Name) if st < service.StatusConfigured { return errors.New("RPC service is not configured") } - client, err := svc.(*rpc.Service).Client() + client, err := svc.(*rrpc.Service).Client() if err != nil { return err } defer client.Close() + if !interactive { + showWorkers(client) + return nil + } + + tm.Clear() + for { + select { + case <-time.NewTicker(time.Millisecond * 500).C: + tm.MoveCursor(1, 1) + showWorkers(client) + tm.Flush() + } + } + + <-stopSignal + return nil +} + +func showWorkers(client *rpc.Client) { var r http.WorkerList if err := client.Call("http.Workers", true, &r); err != nil { panic(err) @@ -63,6 +100,11 @@ func workersHandler(cmd *cobra.Command, args []string) error { tw := tablewriter.NewWriter(os.Stdout) tw.SetHeader([]string{"PID", "Status", "Execs", "Memory", "Created"}) + tw.SetColMinWidth(0, 7) + tw.SetColMinWidth(1, 9) + tw.SetColMinWidth(2, 7) + tw.SetColMinWidth(3, 7) + tw.SetColMinWidth(4, 18) for _, w := range r.Workers { tw.Append([]string{ @@ -75,8 +117,6 @@ func workersHandler(cmd *cobra.Command, args []string) error { } tw.Render() - - return nil } func renderStatus(status string) string { |