summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 18:44:04 +0300
committerWolfy-J <[email protected]>2018-06-10 18:44:04 +0300
commit41ae7e1f8c57075ba19c41f4c5c07da1807f8e1b (patch)
treeba705bbcb83c648ffcdf337864b96b4205fe8d32
parentba99a17a3a7bb88d44fdc6e65001ef0b0dcd6833 (diff)
better workers list
-rw-r--r--cmd/rr/http/workers.go24
-rw-r--r--service/container.go15
2 files changed, 26 insertions, 13 deletions
diff --git a/cmd/rr/http/workers.go b/cmd/rr/http/workers.go
index 62730e25..6083f10c 100644
--- a/cmd/rr/http/workers.go
+++ b/cmd/rr/http/workers.go
@@ -31,7 +31,8 @@ import (
"os"
"strconv"
"time"
- "github.com/fatih/color"
+ "github.com/dustin/go-humanize"
+ "github.com/spiral/roadrunner/cmd/rr/utils"
)
func init() {
@@ -60,11 +61,11 @@ func workersHandler(cmd *cobra.Command, args []string) error {
}
tw := tablewriter.NewWriter(os.Stdout)
- tw.SetHeader([]string{"PID", "Status", "Handled Jobs", "Alive"})
+ tw.SetHeader([]string{"PID", "Status", "Execs", "Created"})
for _, w := range r.Workers {
tw.Append([]string{
- color.YellowString(strconv.Itoa(w.Pid)),
+ strconv.Itoa(w.Pid),
renderStatus(w.Status),
renderJobs(w.NumJobs),
renderAlive(time.Unix(0, w.Created)),
@@ -77,13 +78,26 @@ func workersHandler(cmd *cobra.Command, args []string) error {
}
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 uint64) string {
- return strconv.Itoa(int(number))
+ return humanize.Comma(int64(number))
}
func renderAlive(t time.Time) string {
- return time.Now().Sub(t).String()
+ return humanize.RelTime(t, time.Now(), "ago", "")
}
diff --git a/service/container.go b/service/container.go
index c47e0fd2..1233b30d 100644
--- a/service/container.go
+++ b/service/container.go
@@ -5,7 +5,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"sync"
- "github.com/fatih/color"
)
// Config provides ability to slice configuration sections and unmarshal configuration data into
@@ -65,7 +64,7 @@ func (c *container) Register(name string, service Service) {
status: StatusRegistered,
})
- c.log.Debugf("%s: registered", color.YellowString(name))
+ c.log.Debugf("[%s]: registered", name)
}
// Check hasStatus svc has been registered.
@@ -100,18 +99,18 @@ func (c *container) Get(target string) (svc Service, status int) {
func (c *container) Configure(cfg Config) error {
for _, e := range c.services {
if e.getStatus() >= StatusConfigured {
- return fmt.Errorf("service %s has already been configured", color.RedString(e.name))
+ return fmt.Errorf("service [%s] has already been configured", e.name)
}
segment := cfg.Get(e.name)
if segment == nil {
- c.log.Debugf("%s: no config has been provided", color.YellowString(e.name))
+ c.log.Debugf("[%s]: no config has been provided", e.name)
continue
}
ok, err := e.svc.Configure(segment, c)
if err != nil {
- return errors.Wrap(err, fmt.Sprintf("%s", color.RedString(e.name)))
+ return errors.Wrap(err, fmt.Sprintf("[%s]", e.name))
} else if ok {
e.setStatus(StatusConfigured)
}
@@ -135,13 +134,13 @@ func (c *container) Serve() error {
continue
}
- c.log.Debugf("%s: started", color.GreenString(e.name))
+ c.log.Debugf("[%s]: started", e.name)
go func(e *entry) {
e.setStatus(StatusServing)
defer e.setStatus(StatusStopped)
if err := e.svc.Serve(); err != nil {
- done <- errors.Wrap(err, fmt.Sprintf("%s", color.RedString(e.name)))
+ done <- errors.Wrap(err, fmt.Sprintf("[%s]", e.name))
}
}(e)
}
@@ -165,7 +164,7 @@ func (c *container) Stop() {
if e.hasStatus(StatusServing) {
e.svc.Stop()
e.setStatus(StatusStopped)
- c.log.Debugf("%s: stopped", color.GreenString(e.name))
+ c.log.Debugf("[%s]: stopped", e.name)
}
}
}