Xcp/xenserver Resource Monitoring Script program code

Source: Internet
Author: User
Tags uuid ssh in python

I have always been to a month at least a piece of original technical articles to ask myself, but sometimes really lazy, here to despise himself.
Today is the last day of the month, in fact, the recent work, there are many things can be summed up into the article to share to everyone.

There are some scripts written in Python and Shell that I put on the GitHub, one of which is the Xcp/xenserver resource monitoring script.
Xcp/xenserver's xencenter only clients under Windows, the command line to get the available CPU, memory, and disk, is not so convenient and needs to be acquired through each command line. Some commands must also be run on the host itself, such as XL, so I have ssh-key trusts between the host OS of each xcp/xenserver.

Our environment is made up of more than 10 physical servers loaded with XCP consisting of a Pool,pool manager is the first XCP, and then the storage is used for each of the server's own hard drives.
The results of the script output are as follows:

The code is as follows Copy Code

[Root@xen1 ~]# Vm_monitor
Host Xen1:vm-pdb1a Vm-rdb1b
available:mem=13/95g disk=6/1108g Cpu=18/24cores

Host xen2:vm-pdb1b Vm-rdb1a
available:mem=13/95g disk=6/1108g Cpu=18/24cores

Host xen3:vm-ads10 vm-ads3 vm-api3 vm-cp3 vm-m1 vm-relay1
available:mem=13/63g disk=151/549g Cpu=8/24cores

Host xen4:vm-ads4 vm-c1 vm-log2 VM-MC2
available:mem=22/63g disk=11/549g Cpu=12/24cores

The specific script content is as follows:

The code is as follows Copy Code


host_list=$ (Xe vm-list params | grep "control domain on Host:" | Awk-f ":" ' {print $} ' | Cut-d. -F 1 | SORT-N)

For host in $host _list
  guest_vm=$ (SSH $host xl list-vm |awk ' {print $} ' | GREP-VW name | Sort-n ")
  t_mem_m=$ (SSH $host ' XL info | grep total_memory | cut-d:-F 2 ')
  F_MEM _m=$ (SSH $host ' XL info | grep free_memory | cut-d:-F 2 ')
  t_mem_g=$ (($t _mem_m/1024))
  f_mem_g=$ ($ f_mem_m/1024)
  disk_uuid=$ (Xe sr-list | grep-a 2-b 1 "Local storage" | grep-b 3-w "$HOST" | gre P UUID | Awk-f ":" ' {print $} ')
  t_disk_b=$ (Xe sr-param-list uuid= $disk _uuid | grep physical-size | Cut-d: F 2
  u_disk_b=$ (Xe sr-param-list uuid= $disk _uuid | grep physical-utilisation | cut-d:-F 2)
&nb Sp f_disk_b=$ ($t _disk_b-$u _disk_b))
  t_disk_g=$ (($t _disk_b/1024/1024/1024))
  f_disk_g=$ ($f _disk _b/1024/1024/1024))

  t_cpu_num=$ (ssh $host ' xe host-cpu-info | grep-w cpu_count | awk-f ":" "{print $}")
  v_cpu_sum=0< br>   for VMs in $guest _VM
    vm_uuid=$ (Xe vm-list | grep-b 1-w $VM | head-n 1 | Awk-f ":" ' {print $} ')
    v_cpu_num=$ (Xe vm-list params=vcpus-number Uuid=${vm_uuid} | Grep-w Vcpus | Awk-f ":" ' {print $} ')
    v_cpu_sum=$ (($v _cpu_sum+ $v _cpu_num))
  F_CPU_NU m=$ (($t _cpu_num-$v _cpu_sum))
  echo "
  echo Host $host: $guest _vm
  echo" A vailable:mem=${f_mem_g}/${t_mem_g}g  disk=${f_disk_g}/${t_disk_g}g  CPU=${f_cpu_num}/${t_cpu_num}Cores "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.