[196] | 1 | #!/bin/bash |
---|
| 2 | # Program: |
---|
| 3 | # Check DRBL client status |
---|
| 4 | # Author: |
---|
| 5 | # Jazz, Rock {jazz, rock}@nchc.org.tw |
---|
| 6 | # Version: |
---|
| 7 | # 1.0 |
---|
| 8 | # History: |
---|
| 9 | # 2010/08/29 Rock First release (1.0) |
---|
| 10 | |
---|
| 11 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
| 12 | source $Work_Path/functions_drbl_virt |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | # [Varliables] |
---|
| 16 | client_IPs=$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $1}') |
---|
| 17 | drbl_vm_file="/tmp/drbl_vm_status.$$" |
---|
[199] | 18 | drbl_vm_xentop_file="/tmp/drbl_vm_xentop.$$" |
---|
[222] | 19 | # check Xen or KVM |
---|
| 20 | hypervisior=$(cat $Work_Home/etc/hypervisior) |
---|
[196] | 21 | |
---|
[222] | 22 | |
---|
[196] | 23 | # [Main] |
---|
[200] | 24 | check_root |
---|
[222] | 25 | |
---|
| 26 | case $hypervisior in |
---|
| 27 | "Xen") |
---|
| 28 | for client_IP in $client_IPs |
---|
| 29 | do |
---|
| 30 | # local variables |
---|
| 31 | IP_status="online" |
---|
| 32 | client_hostname="$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | grep $client_IP | awk '{print $2}')" |
---|
| 33 | vm_numbers="" |
---|
| 34 | vm_hostnames="" |
---|
| 35 | vm_IP="" |
---|
| 36 | vm_CPU_core="" |
---|
| 37 | vm_Ram="" |
---|
| 38 | vm_CPU_loading="" |
---|
| 39 | vm_Ram_loading="" |
---|
| 40 | # check network status |
---|
| 41 | ping -c1 -w1 $client_IP > /dev/null 2>&1 || IP_status="offline" |
---|
[196] | 42 | |
---|
[222] | 43 | if [ $IP_status == "online" ]; then |
---|
| 44 | ssh -o StrictHostKeyChecking=no $client_IP "xentop -d1 -b -i2 | awk '/^.*NAME/{i++}i==2'" > $drbl_vm_xentop_file |
---|
| 45 | vm_hostnames="$(cat $drbl_vm_xentop_file | sed -n '3,$p' | awk '{print $1}')" |
---|
[196] | 46 | |
---|
[222] | 47 | # printf "[$client_hostname] " >> $drbl_vm_file |
---|
| 48 | printf "[$client_hostname] " |
---|
| 49 | declare -i i=1 |
---|
[196] | 50 | |
---|
[222] | 51 | vm_numbers=$(echo $vm_hostnames | wc -w) |
---|
[200] | 52 | |
---|
[222] | 53 | # printf "[Running VM: $vm_numbers]\n" >> $drbl_vm_file |
---|
| 54 | printf "[Running VM: $vm_numbers]\n" |
---|
[199] | 55 | |
---|
[222] | 56 | for vm_hostname in $vm_hostnames |
---|
| 57 | do |
---|
| 58 | vm_CPU_core="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $9}')" |
---|
| 59 | vm_Ram="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $5}')" |
---|
| 60 | vm_CPU_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $4}')" |
---|
| 61 | vm_Ram_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $6}')" |
---|
| 62 | # printf "VM$i: $vm_hostname $vm_CPU_core ${vm_Ram}K $vm_CPU_loading%% $vm_Ram_loading%%\n" >> $drbl_vm_file |
---|
| 63 | printf "VM$i: $vm_hostname VCPU=$vm_CPU_core Mem=${vm_Ram}K VCPU_loading=$vm_CPU_loading%% Mem_usage=$vm_Ram_loading%%\n" |
---|
| 64 | i=i+1 |
---|
| 65 | done |
---|
| 66 | echo "" |
---|
| 67 | else |
---|
| 68 | echo "[Error] $client_hostname $client_IP is offline !" |
---|
[200] | 69 | |
---|
[222] | 70 | fi |
---|
[200] | 71 | |
---|
[222] | 72 | done |
---|
| 73 | ;; |
---|
[196] | 74 | |
---|
[222] | 75 | "KVM") |
---|
| 76 | echo "KVM" |
---|
| 77 | ;; |
---|
| 78 | esac |
---|
[199] | 79 | # dlete tmp file |
---|
| 80 | rm -f $drbl_vm_xentop_file |
---|