summaryrefslogtreecommitdiff
path: root/cmd/rr
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 21:17:54 +0300
committerWolfy-J <[email protected]>2018-06-10 21:17:54 +0300
commit7cc6d00a1c350eb3147ede00802d312d4be94dee (patch)
treeac1391c831d4366b477e61b57e095a1dfeafbbb7 /cmd/rr
parente9203e05a7f3278a8080d0f69e6640e5d3d1042d (diff)
debug is not service anymore
Diffstat (limited to 'cmd/rr')
-rw-r--r--cmd/rr/.rr.yaml12
-rw-r--r--cmd/rr/debug/listener.go93
-rw-r--r--cmd/rr/http/workers.go10
-rw-r--r--cmd/rr/main.go16
4 files changed, 117 insertions, 14 deletions
diff --git a/cmd/rr/.rr.yaml b/cmd/rr/.rr.yaml
index cb84af54..29888f69 100644
--- a/cmd/rr/.rr.yaml
+++ b/cmd/rr/.rr.yaml
@@ -33,7 +33,7 @@ http:
# worker pool configuration.
pool:
# number of workers to be serving.
- numWorkers: 1
+ numWorkers: 16
# maximum jobs per worker, 0 - unlimited.
maxJobs: 0
@@ -53,12 +53,4 @@ static:
dir: "c:/GoProj/phpapp/webroot"
# list of extensions for forbid for serving.
- forbid: [".php", ".htaccess"]
-
-# rr debugging
-debug:
- # enable debug output
- enable: true
-
- # show individual worker events
- verbose: true \ No newline at end of file
+ forbid: [".php", ".htaccess"] \ No newline at end of file
diff --git a/cmd/rr/debug/listener.go b/cmd/rr/debug/listener.go
new file mode 100644
index 00000000..fd3b95d3
--- /dev/null
+++ b/cmd/rr/debug/listener.go
@@ -0,0 +1,93 @@
+package debug
+
+import (
+ "github.com/sirupsen/logrus"
+ "github.com/spiral/roadrunner/http"
+ "github.com/spiral/roadrunner/utils"
+ "github.com/spiral/roadrunner"
+)
+
+// Listener provide debug callback for system events. With colors!
+type listener struct{ logger *logrus.Logger }
+
+// NewListener creates new debug listener.
+func NewListener(logger *logrus.Logger) *listener {
+ return &listener{logger}
+}
+
+// Listener listens to http events and generates nice looking output.
+func (s *listener) Listener(event int, ctx interface{}) {
+ // http events
+ switch event {
+ case http.EventResponse:
+ log := ctx.(*http.Log)
+ s.logger.Info(utils.Sprintf("%s <white+hb>%s</reset> %s", statusColor(log.Status), log.Method, log.Uri))
+ case http.EventError:
+ log := ctx.(*http.Log)
+
+ if _, ok := log.Error.(roadrunner.JobError); ok {
+ s.logger.Info(utils.Sprintf("%s <white+hb>%s</reset> %s", statusColor(log.Status), log.Method, log.Uri))
+ } else {
+ s.logger.Info(utils.Sprintf(
+ "%s <white+hb>%s</reset> %s <red>%s</reset>",
+ statusColor(log.Status),
+ log.Method,
+ log.Uri,
+ log.Error,
+ ))
+ }
+ }
+
+ switch event {
+ case roadrunner.EventWorkerKill:
+ w := ctx.(*roadrunner.Worker)
+ s.logger.Warning(utils.Sprintf(
+ "<white+hb>worker.%v</reset> <yellow>killed</red>",
+ *w.Pid,
+ ))
+
+ case roadrunner.EventWorkerError:
+ err := ctx.(roadrunner.WorkerError)
+ s.logger.Error(utils.Sprintf(
+ "<white+hb>worker.%v</reset> <red>%s</reset>",
+ *err.Worker.Pid,
+ err.Caused,
+ ))
+ }
+
+ // rr server events
+ switch event {
+ case roadrunner.EventServerFailure:
+ s.logger.Error(utils.Sprintf("<red>server is dead</reset>"))
+ }
+
+ // pool events
+ switch event {
+ case roadrunner.EventPoolConstruct:
+ s.logger.Debug(utils.Sprintf("<cyan>new worker pool</reset>"))
+ case roadrunner.EventPoolError:
+ s.logger.Error(utils.Sprintf("<red>%s</reset>", ctx))
+ }
+}
+
+// Serve serves.
+func (s *listener) Serve() error { return nil }
+
+// Stop stops the Listener.
+func (s *listener) Stop() {}
+
+func statusColor(status int) string {
+ if status < 300 {
+ return utils.Sprintf("<green>%v</reset>", status)
+ }
+
+ if status < 400 {
+ return utils.Sprintf("<cyan>%v</reset>", status)
+ }
+
+ if status < 500 {
+ return utils.Sprintf("<yellow>%v</reset>", status)
+ }
+
+ return utils.Sprintf("<red+hb>%v</reset>", status)
+}
diff --git a/cmd/rr/http/workers.go b/cmd/rr/http/workers.go
index ddfe337c..3868d748 100644
--- a/cmd/rr/http/workers.go
+++ b/cmd/rr/http/workers.go
@@ -61,7 +61,13 @@ func init() {
rr.CLI.AddCommand(workersCommand)
}
-func workersHandler(cmd *cobra.Command, args []string) error {
+func workersHandler(cmd *cobra.Command, args []string) (err error) {
+ defer func() {
+ if r, ok := recover().(error); ok {
+ err = r
+ }
+ }()
+
svc, st := rr.Container.Get(rrpc.Name)
if st < service.StatusConfigured {
return errors.New("RPC service is not configured")
@@ -136,7 +142,7 @@ func renderStatus(status string) string {
return status
}
-func renderJobs(number uint64) string {
+func renderJobs(number int64) string {
return humanize.Comma(int64(number))
}
diff --git a/cmd/rr/main.go b/cmd/rr/main.go
index 6065d3d1..945b8fa0 100644
--- a/cmd/rr/main.go
+++ b/cmd/rr/main.go
@@ -32,9 +32,13 @@ import (
// cli plugins
_ "github.com/spiral/roadrunner/cmd/rr/http"
- "github.com/spiral/roadrunner/debug"
+ "github.com/spiral/roadrunner/cmd/rr/debug"
+
+ "github.com/spf13/cobra"
)
+var debugMode bool
+
func main() {
// provides ability to make local connection to services
rr.Container.Register(rpc.Name, &rpc.Service{})
@@ -46,7 +50,15 @@ func main() {
rr.Container.Register(static.Name, &static.Service{})
// provides additional verbosity
- rr.Container.Register(debug.Name, &debug.Service{Logger: rr.Logger})
+
+ // debug mode
+ rr.CLI.PersistentFlags().BoolVarP(&debugMode, "debug", "d", false, "debug mode", )
+ cobra.OnInitialize(func() {
+ if debugMode {
+ service, _ := rr.Container.Get(http.Name)
+ service.(*http.Service).AddListener(debug.NewListener(rr.Logger).Listener)
+ }
+ })
// you can register additional commands using cmd.CLI
rr.Execute()