zoukankan      html  css  js  c++  java
  • 批量统计redis内存使用情况

    需求:

    由于redis上云,需要统计一批主机上面的主机内存和redis实例内存使用情况。

    #!/bin/bash
    
    rm -rf redis_mem.log
    
    ps -ef |grep redis-server |grep -v grep | awk '$NF~/cluster/{print $(NF-1);next}{print $NF}' |awk -F':' '{print $2}' >redis_ports
    
    for i in `cat redis_ports`
    do
       redis-cli  -p $i info > info.log
       used_mem=$(grep -w 'used_memory' info.log | awk -F':' '{print $2}' | sed 's/
    //')
       max_mem=$(grep -w 'maxmemory' info.log | awk -F':' '{print $2}' | sed 's/
    //')
       #role=$(grep role info.log | awk -F':' '{print $2}' | sed 's/
    //')
       printf '%10s	 %10s	 %10s	
    ' $i $used_mem $max_mem >> redis_mem.log
    done
    
    host_total_mem=$(free -g | sed -n '2p' | awk '{print $2}')
    redis_used_mem=$(cat redis_mem.log | awk '{sum+=$2}END{printf "%.2f",sum/1024/1024/1024}')
    redis_max_mem=$(cat redis_mem.log | awk '{sum+=$3}END{print sum/1024/1024/1024}')
    redis_host_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}')
    mem_used_pect=$(awk 'BEGIN{printf "%.2f%",'$redis_used_mem'/'$host_total_mem'*100}')
    
    #printf '%20s	 %10s	 %10s	 %10s	 %10s
    ' 主机ip 主机物理内存 redis设置最大内存 本机redis已使用内存 redis使用内存比例 
    printf '%20s	 %10s	 %10s	 %10s	 %10s
    ' $redis_host_ip $host_total_mem $redis_max_mem $redis_used_mem $mem_used_pect

     假设以上脚本名test1.sh,将脚本分发到需要check的主机/tmp目录下

      ansible -i test1  all -m copy -s -a "src=test1.sh dest=/tmp/test1.sh"

    执行结果:ansible -i test1 all -m shell -s -a "sh /tmp/test1.sh" | grep -v 'rc' 

    192.168.100.10            189            120          14.07          7.44%
    192.168.100.11            189            140          16.42          8.69%
    192.168.100.12            189            120          14.33          7.58%
    192.168.100.13            189            120          14.31          7.57%
    192.168.100.14            189            120          14.56          7.70%
    192.168.100.15            189            120          14.32          7.58%
    192.168.100.16            189            130          15.54          8.22%
    192.168.100.17            189            130          15.76          8.34%
  • 相关阅读:
    how to pass a Javabean to server In Model2 architecture.
    What is the Web Appliation Archive, abbreviation is "WAR"
    Understaning Javascript OO
    Genetic Fraud
    poj 3211 Washing Clothes
    poj 2385 Apple Catching
    Magic Star
    关于memset的用法几点
    c++ 函数
    zoj 2972 Hurdles of 110m
  • 原文地址:https://www.cnblogs.com/imdba/p/12843575.html
Copyright © 2011-2022 走看看