| 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.$$" |
|---|
| 18 | drbl_vm_xentop_file="/tmp/drbl_vm_xentop.$$" |
|---|
| 19 | |
|---|
| 20 | # [Main] |
|---|
| 21 | for client_IP in $client_IPs |
|---|
| 22 | do |
|---|
| 23 | # local variables |
|---|
| 24 | IP_status="online" |
|---|
| 25 | client_hostname="$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $2}')" |
|---|
| 26 | vm_numbers="" |
|---|
| 27 | vm_hostnames="" |
|---|
| 28 | vm_IP="" |
|---|
| 29 | vm_CPU_core="" |
|---|
| 30 | vm_Ram="" |
|---|
| 31 | vm_CPU_loading="" |
|---|
| 32 | vm_Ram_loading="" |
|---|
| 33 | # check network status |
|---|
| 34 | ping -c1 -w1 $client_IP > /dev/null 2>&1 || IP_status="offline" |
|---|
| 35 | |
|---|
| 36 | if [ $IP_status == "online" ]; then |
|---|
| 37 | ssh -o StrictHostKeyChecking=no $client_IP "xentop -b -i1" >> $drbl_vm_xentop_file |
|---|
| 38 | vm_hostnames="$(cat $drbl_vm_xentop_file | sed -n '3,$p' | awk '{print $1}')" |
|---|
| 39 | |
|---|
| 40 | printf "[$client_hostname] " >> $drbl_vm_file |
|---|
| 41 | printf "[$client_hostname] " |
|---|
| 42 | declare -i i=1 |
|---|
| 43 | |
|---|
| 44 | vm_numbers=$(echo vm_hostnames | wc -w) |
|---|
| 45 | |
|---|
| 46 | printf "[Running VM: $vm_numbers]\n" >> $drbl_vm_file |
|---|
| 47 | printf "[Running VM: $vm_numbers]\n" |
|---|
| 48 | |
|---|
| 49 | for vm_hostname in $vm_hostnames |
|---|
| 50 | do |
|---|
| 51 | vm_CPU_core="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $9}')" |
|---|
| 52 | vm_Ram="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $5}')" |
|---|
| 53 | vm_CPU_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $4}')" |
|---|
| 54 | vm_Ram_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $6}')" |
|---|
| 55 | printf "VM$i: $vm_hostname $vm_CPU_core ${vm_Ram}M $vm_CPU_loading%% $vm_Ram_loading%%\n" >> $drbl_vm_file |
|---|
| 56 | printf "VM$i: $vm_hostname VCPU=$vm_CPU_core Mem=${vm_Ram}M VCPU_loading=$vm_CPU_loading%% Mem_usage=$vm_Ram_loading%%\n" |
|---|
| 57 | i=i+1 |
|---|
| 58 | done |
|---|
| 59 | |
|---|
| 60 | fi |
|---|
| 61 | done |
|---|
| 62 | |
|---|
| 63 | # dlete tmp file |
|---|
| 64 | rm -f $drbl_vm_xentop_file |
|---|