zoukankan      html  css  js  c++  java
  • buddyinfo 内存碎片数据采集

    不说了,上工具

    #cat    buddyinfo.sh
    #!/bin/sh
    BC_MUTI(){
        #subtraction
        if [[ -n $1 && -n $2 ]];then
            res1=$(printf "%.2f" `echo "scale=2;($1*$2)"|bc`)
            echo $res1
        fi
    }
    
    MESG(){
      local GROUP="$1"
      local KEY=$2
      local VALUE=$3
      local MEASURE=$4
    
      if [[ -n $VALUE ]];then
    	  echo -e "$(date "+%F %H:%M:%S"),$GROUP,$KEY,$VALUE,$MEASURE"  >> $REAL_LOG
    	  return 0
      fi
    }
    
    BC_BUDDY(){
    	aa=$1
    	bb=$2
    	let "res1=$aa*2**$bb"
    	echo $res1
    }
    
    CONVERT_BUDDY_VALUE(){
    	start=$1
    	MAX=`cat /proc/buddyinfo  | grep "Normal"| awk -F"Normal" '{print $2}'|awk '{print NF}'`
    	MAX=`echo "$MAX - 1" | bc`
    	buddy_values=`cat /proc/buddyinfo  | grep "Normal"| awk -F"Normal" '{print $2}'`
    	array2=(
    		$buddy_values
    	)
      bb=`echo ${array2[@]:$start:$MAX}`
    
    	count=0
    	final_vvv=0
    	for value in ${bb[@]};do
    		vvv=`BC_BUDDY $value $count`
    		count=`echo "$count +1 "|bc`
    		final_vvv=`echo "$final_vvv + $vvv"|bc`
    	done
    
    	echo  $final_vvv
    }
    
    LOOP_VMSTAT(){
    	while [[ 0 == 0 ]] ;do
    		sleep 1
    		CALCULATE_VMSTAT
    	done
    }
    
    CALCULATE_VMSTAT(){
    	timestamp=$(date "+%Y-%m-%d-%H:%M:%S")
    	order1=`CONVERT_BUDDY_VALUE 1`
    	order2=`CONVERT_BUDDY_VALUE 2`
    	order3=`CONVERT_BUDDY_VALUE 3`
    	order4=`CONVERT_BUDDY_VALUE 4`
    	order5=`CONVERT_BUDDY_VALUE 5`
    	order6=`CONVERT_BUDDY_VALUE 6`
    	order7=`CONVERT_BUDDY_VALUE 7`
    	order8=`CONVERT_BUDDY_VALUE 8`
    	order9=`CONVERT_BUDDY_VALUE 9`
    	order10=`CONVERT_BUDDY_VALUE 10`
    	printf "%-20s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s
    " $timestamp $order1 $order2 $order3 $order4 $order5 $order6 $order7 $order8 $order9 $order10
    }
    main(){
    	 printf "%-20s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s
    " "timestamp" "order1" "order2" "order3" "order4" "order5" "order6" "order7" "order8" "order9" "order10"
    	 LOOP_VMSTAT
    }
    main
    
    
    [root@host /home/ahao.mah]
    #sh   buddyinfo.sh
    timestamp            order1  order2  order3  order4  order5  order6  order7  order8  order9  order10
    
    2017-04-26-20:53:20  9952240 4975948 2487866 1243711 621496  309892  154207  76867   38313   19124
    2017-04-26-20:53:22  9952309 4975928 2487861 1243712 621496  309892  154207  76867   38313   19124
    2017-04-26-20:53:23  9952392 4975970 2487869 1243713 621496  309892  154207  76867   38313   19124
    2017-04-26-20:53:24  9952429 4975992 2487877 1243713 621496  309892  154207  76867   38313   19124
    2017-04-26-20:53:26  9952449 4975993 2487879 1243713 621496  309892  154207  76867   38313   19124
    2017-04-26-20:53:27  9952485 4975998 2487880 1243713 621496  309892  154207  76867   38313   19124
    2017-04-26-20:53:28  9952490 4976003 2487883 1243715 621497  309892  154207  76867   38313   19124
    2017-04-26-20:53:29  9952475 4975996 2487882 1243716 621498  309892  154207  76867   38313   19124
    2017-04-26-20:53:31  9952404 4975956 2487881 1243716 621498  309892  154207  76867   38313   19124
    2017-04-26-20:53:32  9952494 4975998 2487886 1243716 621498  309892  154207  76867   38313   19124
    

  • 相关阅读:
    程序员开发工作之算法和架构
    iOS开发学习概述及知识整理
    git基本技巧及进阶
    使用命令行工具运行Xcode 7 UI Tests
    技巧集锦2
    Xcode开发小问题集锦
    Xcode 7如何 免费 真机调试iOS应用
    常用shell script 珍藏
    多线程学习7--CountDownLatch
    学习多线程6---栅栏
  • 原文地址:https://www.cnblogs.com/muahao/p/6770014.html
Copyright © 2011-2022 走看看