From d24c43aaeff897394eca140478c73dd146f8710a Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Wed, 26 Sep 2018 22:18:48 +0300 Subject: worker information extraction is now moved to external package --- cmd/rr/http/workers.go | 61 ++------------------------------------------------ 1 file changed, 2 insertions(+), 59 deletions(-) (limited to 'cmd/rr/http/workers.go') diff --git a/cmd/rr/http/workers.go b/cmd/rr/http/workers.go index b03c273f..3c3e9987 100644 --- a/cmd/rr/http/workers.go +++ b/cmd/rr/http/workers.go @@ -23,19 +23,15 @@ package http import ( "errors" tm "github.com/buger/goterm" - "github.com/dustin/go-humanize" - "github.com/olekukonko/tablewriter" - "github.com/shirou/gopsutil/process" "github.com/spf13/cobra" rr "github.com/spiral/roadrunner/cmd/rr/cmd" - "github.com/spiral/roadrunner/cmd/rr/utils" + "github.com/spiral/roadrunner/cmd/rr/util" "github.com/spiral/roadrunner/service" "github.com/spiral/roadrunner/service/http" rrpc "github.com/spiral/roadrunner/service/rpc" "net/rpc" "os" "os/signal" - "strconv" "syscall" "time" ) @@ -108,58 +104,5 @@ func showWorkers(client *rpc.Client) { panic(err) } - 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{ - strconv.Itoa(w.Pid), - renderStatus(w.Status), - renderJobs(w.NumJobs), - renderMemory(w.Pid), - renderAlive(time.Unix(0, w.Created)), - }) - } - - tw.Render() -} - -func renderStatus(status string) string { - switch status { - case "inactive": - return utils.Sprintf("inactive") - case "ready": - return utils.Sprintf("ready") - case "working": - return utils.Sprintf("working") - case "stopped": - return utils.Sprintf("stopped") - case "errored": - return utils.Sprintf("errored") - } - - return status -} - -func renderJobs(number int64) string { - return humanize.Comma(int64(number)) -} - -func renderAlive(t time.Time) string { - return humanize.RelTime(t, time.Now(), "ago", "") -} - -func renderMemory(pid int) string { - p, _ := process.NewProcess(int32(pid)) - i, err := p.MemoryInfo() - if err != nil { - return err.Error() - } - - return humanize.Bytes(i.RSS) + util.WorkerTable(r.Workers).Render() } -- cgit v1.2.3 From a206fc3270ea6e469b1704f15f2f15a9f6a14bbd Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Wed, 26 Sep 2018 22:30:53 +0300 Subject: improved debug handlers --- cmd/rr/http/workers.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'cmd/rr/http/workers.go') diff --git a/cmd/rr/http/workers.go b/cmd/rr/http/workers.go index 3c3e9987..4444b87f 100644 --- a/cmd/rr/http/workers.go +++ b/cmd/rr/http/workers.go @@ -21,14 +21,11 @@ package http import ( - "errors" tm "github.com/buger/goterm" "github.com/spf13/cobra" rr "github.com/spiral/roadrunner/cmd/rr/cmd" - "github.com/spiral/roadrunner/cmd/rr/util" - "github.com/spiral/roadrunner/service" + "github.com/spiral/roadrunner/cmd/util" "github.com/spiral/roadrunner/service/http" - rrpc "github.com/spiral/roadrunner/service/rpc" "net/rpc" "os" "os/signal" @@ -69,12 +66,7 @@ func workersHandler(cmd *cobra.Command, args []string) (err error) { } }() - svc, st := rr.Container.Get(rrpc.ID) - if st < service.StatusOK { - return errors.New("RPC service is not configured") - } - - client, err := svc.(*rrpc.Service).Client() + client, err := util.RPCClient(rr.Container) if err != nil { return err } -- cgit v1.2.3