source: drbl-virt/sbin/check_drbl_vm @ 207

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

Rename: Change to short name

  • Property svn:executable set to *
File size: 2.3 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
20# [Main]
21check_root
22for client_IP in $client_IPs
23do
24    # local variables
25    IP_status="online"
26    client_hostname="$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | grep $client_IP | awk '{print $2}')"
27    vm_numbers=""
28    vm_hostnames=""
29    vm_IP=""
30    vm_CPU_core=""
31    vm_Ram=""
32    vm_CPU_loading=""
33    vm_Ram_loading=""
34    # check network status
35    ping -c1 -w1 $client_IP > /dev/null 2>&1 || IP_status="offline"
36   
37    if [ $IP_status == "online" ]; then
38        ssh -o StrictHostKeyChecking=no $client_IP "xentop -d1 -b -i2 | awk '/^.*NAME/{i++}i==2'" > $drbl_vm_xentop_file
39        vm_hostnames="$(cat $drbl_vm_xentop_file | sed -n '3,$p' | awk '{print $1}')"
40   
41#        printf "[$client_hostname] " >> $drbl_vm_file
42        printf "[$client_hostname] "
43        declare -i i=1
44
45        vm_numbers=$(echo $vm_hostnames | wc -w)
46
47#        printf "[Running VM: $vm_numbers]\n" >> $drbl_vm_file
48        printf "[Running VM: $vm_numbers]\n"
49
50        for vm_hostname in $vm_hostnames
51        do 
52            vm_CPU_core="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $9}')"
53            vm_Ram="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $5}')"
54            vm_CPU_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $4}')"
55            vm_Ram_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $6}')"
56#            printf "VM$i: $vm_hostname $vm_CPU_core ${vm_Ram}K $vm_CPU_loading%% $vm_Ram_loading%%\n" >> $drbl_vm_file
57            printf "VM$i: $vm_hostname VCPU=$vm_CPU_core Mem=${vm_Ram}K VCPU_loading=$vm_CPU_loading%% Mem_usage=$vm_Ram_loading%%\n"
58            i=i+1
59        done
60        echo "" 
61    else
62        echo "[Error] $client_hostname $client_IP is offline !"
63
64    fi
65
66done
67
68# dlete tmp file
69rm -f $drbl_vm_xentop_file
Note: See TracBrowser for help on using the repository browser.