2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 07:12:17 +08:00

Add command "asynqmon" for monitoring

This commit is contained in:
Ken Hibino 2019-12-03 20:02:29 -08:00
parent 319d157d47
commit 593f2b0482
2 changed files with 43 additions and 2 deletions

41
cmd/asynqmon/main.go Normal file
View File

@ -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()
}

View File

@ -6,9 +6,9 @@ type Inspector struct {
} }
// NewInspector returns a new Inspector instance. // NewInspector returns a new Inspector instance.
func NewInspector(opt *RedisOpt) *Inspector { func NewInspector(config *RedisConfig) *Inspector {
return &Inspector{ return &Inspector{
rdb: newRDB(opt), rdb: newRDB(config),
} }
} }