• xenserver 主机cpu一段时间内的使用情况


    #!/bin/sh
    #this script for get xenserver 6.5 7.0  cpu useage
    #send xen-host-cpu.sh to xenserver use ftp or ssh first  ./xen-host-cpu.sh
    #version: 0.03
    #date:  2016-01-11 hayden
    #yelang007sheng@163.com
    
    log=`date "+%H_%M_%S"`
    
    get_host_uuid(){
    
    host_uuid=`xe host-list |grep uuid |awk -F: '{print $2}' |sed 's/ //g'`
    #host_uuid=`xe host-list --minimal`
    sleep 1
    
    }
    
    get_host_cpu_avg(){
    
    rrd2csv AVERAGE:host:"$host_uuid":cpu_avg >host_cpu_avg_"$log" & >/dev/null
    rrd2csv_cpu_pid=$!
    
    }
    
    monitor_time(){
    while :
    do
        read -p "Please input a monitor time:[ exp> 60s or 5m or 1h or 1d ] " time
        # ???use && not executed 
        if [ `echo "${time:0:${#time}-1}" |grep -c '[^0-9]'` -ne 0 ] || [ `echo "${time:0-1}" |grep -c '[smhd]'` -ne 1 ]; then
            echo "Input monitor time error!!!"
            continue
        else
            if [ "${time:0:${#time}-1}" -gt 0 ]; then
                break
            else
                echo "Input monitor time error!!!"
                continue
            fi
        fi
    done
    }
    
    #main
    
    monitor_time
    get_host_uuid
    get_host_cpu_avg
    echo "Monitor start ... Please wait $time "
    sleep $time
    sleep 1
    kill -9 $rrd2csv_cpu_pid >/dev/null 2>&1
    sleep 2
    cp host_cpu_avg_"$log" cpu_temp_"$log"
    sed -i '1d' cpu_temp_"$log"
    
    cat cpu_temp_"$log" |awk -F\, '{print $2}' |sed 's/ //g' | sort -n >temp_"$log"
    min_cpu_t=`head -n 1 temp_"$log"`
    min_cpu=`echo "scale=2; $min_cpu_t * 100"|bc |awk '{printf "%.2f", $0}'`
    max_cpu_t=`tail -n 1 temp_"$log"`
    max_cpu=`echo "scale=2; $max_cpu_t * 100"|bc |awk '{printf "%.2f", $0}'`
    count_temp=`cat temp_"$log" |wc -l`
    
    sum=0
    for i in `cat temp_"$log"`
    do
        sum=`echo $sum + $i |bc`
    done
    
    
    avg_cpu_t=`echo "scale=4; $sum / $count_temp "|bc |awk '{printf "%.4f", $0}'`
    avg_cpu=`echo "scale=2; $avg_cpu_t * 100"|bc |awk '{printf "%.2f", $0}'`
    
    echo Host["$host_uuid"] min_cpu="$min_cpu""%" |tee host_cpu_"$log"
    echo Host["$host_uuid"] max_cpu="$max_cpu""%" |tee -a host_cpu_"$log"
    echo Host["$host_uuid"] avg_cpu="$avg_cpu""%" |tee -a host_cpu_"$log"
    
    mkdir -p /tmp/"$log"
    mv host_cpu_avg_"$log" host_cpu_"$log" /tmp/"$log" 
    rm -rf  cpu_temp_"$log" temp_"$log"  
  • 相关阅读:
    Redis详解
    Redis详细介绍
    memcache数据组织
    memcache细节解析
    memcached命令和配置
    PHP的Cookie、Session和跟Laravel相关的几点了解
    Session机制
    Cookie和Session详解
    Apache的Directory配置指南
    [C语言](二)01 获取Windows图形构件大小信息
  • 原文地址:https://www.cnblogs.com/hayden1106/p/8005469.html
Copyright © 2020-2023  润新知