summaryrefslogtreecommitdiff
path: root/cmd/rr/http
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/rr/http')
-rw-r--r--cmd/rr/http/reset.go6
-rw-r--r--cmd/rr/http/workers.go61
2 files changed, 5 insertions, 62 deletions
diff --git a/cmd/rr/http/reset.go b/cmd/rr/http/reset.go
index 3bc089ec..f1129eef 100644
--- a/cmd/rr/http/reset.go
+++ b/cmd/rr/http/reset.go
@@ -24,7 +24,7 @@ import (
"errors"
"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/rpc"
)
@@ -49,13 +49,13 @@ func reloadHandler(cmd *cobra.Command, args []string) error {
}
defer client.Close()
- utils.Printf("<green>restarting http worker pool</reset>: ")
+ util.Printf("<green>restarting http worker pool</reset>: ")
var r string
if err := client.Call("http.Reset", true, &r); err != nil {
return err
}
- utils.Printf("<green+hb>done</reset>\n")
+ util.Printf("<green+hb>done</reset>\n")
return nil
}
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("<yellow>inactive</reset>")
- case "ready":
- return utils.Sprintf("<cyan>ready</reset>")
- case "working":
- return utils.Sprintf("<green>working</reset>")
- case "stopped":
- return utils.Sprintf("<red>stopped</reset>")
- case "errored":
- return utils.Sprintf("<red>errored</reset>")
- }
-
- 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()
}