source: drbl-virt/sbin/check_drbl_vm @ 223

Last change on this file since 223 was 223, checked in by rock, 14 years ago

Rename:

  • Property svn:executable set to *
File size: 2.6 KB
Line 
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
11source /opt/drbl-virt/conf/drbl-virt.conf
12source $Work_Path/functions_drbl_virt
13
14
15# [Varliables]
16client_IPs=$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $1}')
17drbl_vm_file="/tmp/drbl_vm_status.$$"
18drbl_vm_xentop_file="/tmp/drbl_vm_xentop.$$"
19# check Xen or KVM
20hypervisior=$(cat $Work_Home/etc/hypervisior)
21
22
23# [Main]
24check_root
25
26case $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"
42   
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}')"
46   
47            # printf "[$client_hostname] " >> $drbl_vm_file
48            printf "[$client_hostname] "
49            declare -i i=1
50
51            vm_numbers=$(echo $vm_hostnames | wc -w)
52
53           # printf "[Running VM: $vm_numbers]\n" >> $drbl_vm_file
54            printf "[Running VM: $vm_numbers]\n"
55
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 !"
69
70        fi
71
72    done
73    ;;
74
75    "KVM")
76        echo "KVM"
77    ;;
78esac
79# dlete tmp file
80rm -f $drbl_vm_xentop_file
Note: See TracBrowser for help on using the repository browser.