前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >查看Redis集群所有节点内存工具

查看Redis集群所有节点内存工具

作者头像
一见
发布2018-09-30 11:16:27
2.5K0
发布2018-09-30 11:16:27
举报
文章被收录于专栏:蓝天蓝天

指定集群中任意一个节点,查看集群中所有节点当前已用物理内存、配置的最大物理内存和系统物理内存。 源码(可从下载):

  1. #!/bin/bash
  2. # Query the memory of all nodes in a cluster
  3. #
  4. # Output example:
  5. # $ ./query_redis_cluster.sh 192.168.0.31.21:6379
  6. # [192.168.0.31.21:6379] Used: 788.57M Max: 15.00G System: 125.56G
  7. # [192.168.0.31.22:6380] Used: 756.98M Max: 15.00G System: 125.56G
  8. # [192.168.0.31.23:6380] Used: 743.93M Max: 15.00G System: 125.56G
  9. # [192.168.0.31.24:6380] Used: 21.73M Max: 15.00G System: 125.56G
  10. # [192.168.0.31.25:6380] Used: 819.11M Max: 15.00G System: 125.56G
  11. # [192.168.0.31.24:6379] Used: 771.70M Max: 15.00G System: 125.56G
  12. # [192.168.0.31.26:6379] Used: 920.77M Max: 15.00G System: 125.56G
  13. # [192.168.0.31.27:6380] Used: 889.09M Max: 15.00G System: 125.27G
  14. # [192.168.0.31.28:6379] Used: 741.24M Max: 15.00G System: 125.56G
  15. # [192.168.0.31.29:6380] Used: 699.55M Max: 15.00G System: 125.56G
  16. # [192.168.0.31.27:6379] Used: 752.89M Max: 15.00G System: 125.27G
  17. # [192.168.0.31.21:6380] Used: 716.05M Max: 15.00G System: 125.56G
  18. # [192.168.0.31.23:6379] Used: 784.82M Max: 15.00G System: 125.56G
  19. # [192.168.0.31.26:6380] Used: 726.40M Max: 15.00G System: 125.56G
  20. # [192.168.0.31.25:6379] Used: 726.09M Max: 15.00G System: 125.56G
  21. # [192.168.0.31.29:6379] Used: 844.59M Max: 15.00G System: 125.56G
  22. # [192.168.0.31.28:6380] Used: 14.00M Max: 15.00G System: 125.56G
  23. # [192.168.0.31.22:6379] Used: 770.13M Max: 15.00G System: 125.56G
  24. REDIS_CLI=${REDIS_CLI:-redis-cli}
  25. REDIS_IP=${REDIS_IP:-127.0.0.1}
  26. REDIS_PORT=${REDIS_PORT:-6379}
  27. function usage()
  28. {
  29. echo "Usage: `basename $0` redis_node"
  30. echo "Example: `basename $0` 127.0.0.1:6379"
  31. }
  32. # with a parameter: single redis node
  33. if test $# -ne 1; then
  34. usage
  35. exit 1
  36. fi
  37. eval $(echo "$1" | awk -F[\:] '{ printf("REDIS_IP=%s\nREDIS_PORT=%s\n",$1,$2) }')
  38. if test -z "$REDIS_IP" -o -z "$REDIS_PORT"; then
  39. echo "Parameter error"
  40. usage
  41. exit 1
  42. fi
  43. # 确保redis-cli可用
  44. which "$REDIS_CLI" > /dev/null 2>&1
  45. if test $? -ne 0; then
  46. echo "\`redis-cli\` not exists or not executable"
  47. exit 1
  48. fi
  49. redis_nodes=`redis-cli -h $REDIS_IP -p $REDIS_PORT cluster nodes | awk -F[\ \:\@] '!/ERR/{ printf("%s:%s\n",$2,$3); }'`
  50. if test -z "$redis_nodes"; then
  51. # standlone
  52. $REDIS_CLI -h $REDIS_IP -p $REDIS_PORT FLUSHALL
  53. else
  54. # cluster
  55. for redis_node in $redis_nodes;
  56. do
  57. if test ! -z "$redis_node"; then
  58. eval $(echo "$redis_node" | awk -F[\:] '{ printf("redis_node_ip=%s\nredis_node_port=%s\n",$1,$2) }')
  59. if test ! -z "$redis_node_ip" -a ! -z "$redis_node_port"; then
  60. items=(`$REDIS_CLI -h $redis_node_ip -p $redis_node_port INFO MEMORY 2>&1 | tr '\r' ' '`)
  61. used_memory_rss_human=0
  62. maxmemory_human=0
  63. total_system_memory_human=0
  64. for item in "${items[@]}"
  65. do
  66. eval $(echo "$item" | awk -F[\:] '{ printf("name=%s\nvalue=%s\n",$1,$2) }')
  67. if test "$name" = "used_memory_rss_human"; then
  68. used_memory_rss_human=$value
  69. elif test "$name" = "maxmemory_human"; then
  70. maxmemory_human=$value
  71. elif test "$name" = "total_system_memory_human"; then
  72. total_system_memory_human=$value
  73. fi
  74. done
  75. echo -e "[\033[1;33m${redis_node_ip}:${redis_node_port}\033[m]\tUsed: \033[0;32;32m$used_memory_rss_human\033[m\tMax: \033[0;32;32m$maxmemory_human\033[m\tSystem: \033[0;32;32m$total_system_memory_human\033[m"
  76. fi
  77. fi
  78. done
  79. fi
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-09-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档