mirror of
https://github.com/hibiken/asynq.git
synced 2024-11-10 11:31:58 +08:00
Display cluster info in stats command when --cluster flag is passed
This commit is contained in:
parent
818c2d6f35
commit
c26b7469bd
@ -222,8 +222,21 @@ func (r *RDB) RedisInfo() (map[string]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseInfo(res)
|
||||
}
|
||||
|
||||
// RedisClusterInfo returns a map of redis cluster info.
|
||||
func (r *RDB) RedisClusterInfo() (map[string]string, error) {
|
||||
res, err := r.client.ClusterInfo().Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseInfo(res)
|
||||
}
|
||||
|
||||
func parseInfo(infoStr string) (map[string]string, error) {
|
||||
info := make(map[string]string)
|
||||
lines := strings.Split(res, "\r\n")
|
||||
lines := strings.Split(infoStr, "\r\n")
|
||||
for _, l := range lines {
|
||||
kv := strings.Split(l, ":")
|
||||
if len(kv) == 2 {
|
||||
|
@ -6,6 +6,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -88,7 +89,12 @@ func stats(cmd *cobra.Command, args []string) {
|
||||
aggStats.Timestamp = s.Timestamp
|
||||
stats = append(stats, s)
|
||||
}
|
||||
info, err := r.RedisInfo()
|
||||
var info map[string]string
|
||||
if useRedisCluster {
|
||||
info, err = r.RedisClusterInfo()
|
||||
} else {
|
||||
info, err = r.RedisInfo()
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
@ -105,8 +111,13 @@ func stats(cmd *cobra.Command, args []string) {
|
||||
printSuccessFailureStats(&aggStats)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("REDIS INFO")
|
||||
printInfo(info)
|
||||
if useRedisCluster {
|
||||
fmt.Println("REDIS CLUSTER INFO")
|
||||
printClusterInfo(info)
|
||||
} else {
|
||||
fmt.Println("REDIS INFO")
|
||||
printInfo(info)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@ -174,6 +185,19 @@ func printInfo(info map[string]string) {
|
||||
tw.Flush()
|
||||
}
|
||||
|
||||
func printClusterInfo(info map[string]string) {
|
||||
printTable(
|
||||
[]string{"State", "Known Nodes", "Cluster Size"},
|
||||
func(w io.Writer, tmpl string) {
|
||||
fmt.Fprintf(w, tmpl,
|
||||
strings.ToUpper(info["cluster_state"]),
|
||||
info["cluster_known_nodes"],
|
||||
info["cluster_size"],
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func toInterfaceSlice(strs []string) []interface{} {
|
||||
var res []interface{}
|
||||
for _, s := range strs {
|
||||
|
Loading…
Reference in New Issue
Block a user