diff options
author | Valery Piashchynski <[email protected]> | 2021-04-20 10:06:45 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-20 10:06:45 +0300 |
commit | 3362f211f6358d60bea47ac2de4cc29a47373973 (patch) | |
tree | d36dc3ce9a36fff1b15b8795e8fa08d397317d14 /tools/worker_table.go | |
parent | 35d6a50aa3640c870b99c120b26c9b9012b424be (diff) | |
parent | 779cc3f5aebb749ab4bc6190e03cc86ff3f151a0 (diff) |
#634 feat(plugin): new plugin `service`v2.1.0-beta.2
feat(plugin): new plugin `service`
Diffstat (limited to 'tools/worker_table.go')
-rw-r--r-- | tools/worker_table.go | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/tools/worker_table.go b/tools/worker_table.go index 157aa972..4dd70d8e 100644 --- a/tools/worker_table.go +++ b/tools/worker_table.go @@ -8,31 +8,62 @@ import ( "github.com/dustin/go-humanize" "github.com/fatih/color" "github.com/olekukonko/tablewriter" + "github.com/spiral/roadrunner/v2/pkg/process" ) // WorkerTable renders table with information about rr server workers. -func WorkerTable(writer io.Writer, workers []ProcessState) *tablewriter.Table { +func WorkerTable(writer io.Writer, workers []process.State) *tablewriter.Table { tw := tablewriter.NewWriter(writer) - tw.SetHeader([]string{"PID", "Status", "Execs", "Memory", "Created"}) + tw.SetHeader([]string{"PID", "Status", "Execs", "Memory", "CPU%", "Created"}) tw.SetColMinWidth(0, 7) tw.SetColMinWidth(1, 9) tw.SetColMinWidth(2, 7) tw.SetColMinWidth(3, 7) - tw.SetColMinWidth(4, 18) + tw.SetColMinWidth(4, 7) + tw.SetColMinWidth(5, 18) - for key := range workers { + for i := 0; i < len(workers); i++ { tw.Append([]string{ - strconv.Itoa(workers[key].Pid), - renderStatus(workers[key].Status), - renderJobs(workers[key].NumJobs), - humanize.Bytes(workers[key].MemoryUsage), - renderAlive(time.Unix(0, workers[key].Created)), + strconv.Itoa(workers[i].Pid), + renderStatus(workers[i].Status), + renderJobs(workers[i].NumJobs), + humanize.Bytes(workers[i].MemoryUsage), + renderCPU(workers[i].CPUPercent), + renderAlive(time.Unix(0, workers[i].Created)), }) } return tw } +// ServiceWorkerTable renders table with information about rr server workers. +func ServiceWorkerTable(writer io.Writer, workers []process.State) *tablewriter.Table { + tw := tablewriter.NewWriter(writer) + tw.SetAutoWrapText(false) + tw.SetHeader([]string{"PID", "Memory", "CPU%", "Command"}) + tw.SetColMinWidth(0, 7) + tw.SetColMinWidth(1, 7) + tw.SetColMinWidth(2, 7) + tw.SetColMinWidth(3, 18) + tw.SetAlignment(tablewriter.ALIGN_LEFT) + + for i := 0; i < len(workers); i++ { + tw.Append([]string{ + strconv.Itoa(workers[i].Pid), + humanize.Bytes(workers[i].MemoryUsage), + renderCPU(workers[i].CPUPercent), + workers[i].Command, + }) + } + + return tw +} + +//go:inline +func renderCPU(cpu float64) string { + return strconv.FormatFloat(cpu, 'f', 2, 64) +} + func renderStatus(status string) string { switch status { case "inactive": |