2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-13 04:46:39 +08:00
asynq/cmd/asynqmon/main.go

39 lines
802 B
Go
Raw Normal View History

2019-12-04 12:02:29 +08:00
package main
import (
"fmt"
"log"
"os"
"strings"
"text/tabwriter"
2019-12-04 13:01:26 +08:00
"github.com/go-redis/redis/v7"
"github.com/hibiken/asynq/internal/rdb"
2019-12-04 12:02:29 +08:00
)
2019-12-06 09:14:35 +08:00
// Example usage: watch -n5 asynqmon
2019-12-04 12:02:29 +08:00
func main() {
2019-12-04 13:01:26 +08:00
c := redis.NewClient(&redis.Options{
2019-12-04 12:02:29 +08:00
Addr: "localhost:6379",
DB: 2,
})
2019-12-04 23:18:15 +08:00
r := rdb.NewRDB(c)
2019-12-04 12:02:29 +08:00
2019-12-06 09:14:35 +08:00
stats, err := r.CurrentStats()
if err != nil {
log.Fatal(err)
2019-12-04 12:02:29 +08:00
}
2019-12-06 09:14:35 +08:00
printStats(stats)
fmt.Println()
2019-12-04 12:02:29 +08:00
}
2019-12-04 13:01:26 +08:00
func printStats(s *rdb.Stats) {
2019-12-04 12:02:29 +08:00
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, "--------", "----------", "---------", "-----", "----")
2019-12-05 08:56:10 +08:00
fmt.Fprintf(tw, format, s.Enqueued, s.InProgress, s.Scheduled, s.Retry, s.Dead)
2019-12-04 12:02:29 +08:00
tw.Flush()
}