From 593f2b04824f6cb5356f7cbd04c1c86916c4dc75 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Tue, 3 Dec 2019 20:02:29 -0800 Subject: [PATCH] Add command "asynqmon" for monitoring --- cmd/asynqmon/main.go | 41 +++++++++++++++++++++++++++++++++++++++++ inspector.go | 4 ++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 cmd/asynqmon/main.go diff --git a/cmd/asynqmon/main.go b/cmd/asynqmon/main.go new file mode 100644 index 0000000..72c826d --- /dev/null +++ b/cmd/asynqmon/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + "strings" + "text/tabwriter" + "time" + + "github.com/hibiken/asynq" +) + +var pollInterval = flag.Duration("interval", 3*time.Second, "polling interval") + +func main() { + inspector := asynq.NewInspector(&asynq.RedisConfig{ + Addr: "localhost:6379", + DB: 2, + }) + + for { + stats, err := inspector.CurrentStats() + if err != nil { + log.Fatal(err) + } + printStats(stats) + fmt.Println() + time.Sleep(*pollInterval) + } +} + +func printStats(s *asynq.Stats) { + format := strings.Repeat("%v\t", 5) + "\n" + tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0) + fmt.Fprintf(tw, format, "Enqueued", "InProgress", "Scheduled", "Retry", "Dead") + fmt.Fprintf(tw, format, "--------", "----------", "---------", "-----", "----") + fmt.Fprintf(tw, format, s.Queued, s.InProgress, s.Scheduled, s.Retry, s.Dead) + tw.Flush() +} diff --git a/inspector.go b/inspector.go index fe4dbb7..39697cc 100644 --- a/inspector.go +++ b/inspector.go @@ -6,9 +6,9 @@ type Inspector struct { } // NewInspector returns a new Inspector instance. -func NewInspector(opt *RedisOpt) *Inspector { +func NewInspector(config *RedisConfig) *Inspector { return &Inspector{ - rdb: newRDB(opt), + rdb: newRDB(config), } }