[zabbix] Monitor the growth and occupancy of virtual machine hard disks on ESXi s

Because the company used to take hardware heap out of the environment now want to virtualize, so most of our current environment is through the P2V to free the original machine, install ESXi and then run on the local hard disk virtual machine. I also know it is very unsafe, so we need to face several problems before the node configuration of the hard disk empty. There is not much memory and hard disk, so it will be very hard for us to run the virtual machine. Of course, it's a bit of a performance problem when memory runs full, but it's an awkward problem when the hard disk runs full of virtual machines on the whole node. So in order to prevent this problem from happening, at the beginning, I wrote an article on how to monitor the amount of hard disk space of nodes. Bread the ESXi Hard Disk Monitoring script and explain how to use it in detail. http://mianbao.cn.com/forum.php?mod=viewthread&tid=173&fromuid=1 The use of the script is also explained.

But then we found that only this monitoring is not enough for the node hard disk to reach the alarm threshold, how to take measures has become our biggest problem because we can not quickly locate which virtual machine occupies a large amount of hard disk space, so we can not achieve agile reflection. Because it also involves virtual machine migration, which is needed to communicate with the business. If you don't have strong evidence that it's a problem with a virtual machine, communication will be difficult. So bread wrote a script to monitor the virtual machine on each node.




The emphasis is not on the graph, but on the value below, we can quickly locate how much space the virtual machine on this node adds in a certain period of time because we are all using thin allocation and it is difficult to control the ratio of excess points in the case of resource constraints. In addition, it should be noted that this value is to monitor the size of the entire virtual machine, including memory files, mirror snapshots, VMDK, log and other space occupied on the node. Another thing to note is that VMware does not have a hard disk recycling mechanism. For example, I thin allocation of a hard disk for 300G. I really used 150G. Suddenly one day I cleaned up the logs for 20G. You saw that you only occupied 130G in the system, but at the bottom you still occupied 150G. This value is shown here.

After that, let's take a look at the process of implementation together with my requirements and the effect of implementation. Let's first look at how the script was written.
#-*- coding:utf-8 -*-
'''
@Created on 2016
 
@author: MianBao

@author_web: Mianbao.cn.com

'''
import copy
import ssl
from pysphere import VIServer,VIProperty
from zabbix_send import zabbix_sender



def GetNodeInfo(Server):
    managed_object_types = 'VirtualMachine'
    properties = [
    'summary.runtime.host',
    'summary.storage.committed',
    'name',
    ]
    props = Server._retrieve_properties_traversal(property_names=properties,obj_type=managed_object_types)
    vms = dict()
    for item in props:
        vm = {}
        host_id = None
        for p in item.PropSet:
            if p.Name == 'summary.runtime.host':
                if vms.get(p.Val,None):
                    host_id = p.Val
            vm[p.Name] = p.Val
        if host_id:
            vms[host_id].append(vm)
        else:
            vms[vm['summary.runtime.host']] = [vm,]
    return vms
            
def GetHosts(s):
    hosts = s.get_hosts()
    return hosts

def main(s,zabbix_info):
    hosts = GetHosts(s)
    vms = GetNodeInfo(s)
    for x,y in vms.items():
        for m in y:
            response = SendData(x,m,hosts,zabbix_info)
            print response
    return response

def SendData(x,m,hosts,zabbix_info):
    zabbix_vm = zabbix_sender(**zabbix_info)
    
    value = dict()
    value['host'] = hosts.get(x,None)
    value['key'] = 'vmware.vm'
    vm_name = m.get('name')
    value['value'] = '{"data":[{"{#DATA}":"%s"}]}' % str(vm_name)
    zabbix_vm.adddata(**copy.deepcopy(value))
    print hosts.get(x,None),'--------',vm_name
    for key,val in m.items():
        if key not in ['summary.runtime.host','name',]:
            value['key'] = '%s[%s]' % (key, vm_name)
            value['value'] = val
            zabbix_vm.adddata(**copy.deepcopy(value))
    
    response=zabbix_vm.send()
    return response

The main code for the above implementation also needs to call this function under "get_disk_info.py". Next, let's look at how to set up a new "discovery rules" in the template and then set the key as shown in the following figure
 
Set "discovery rules" and set its item as follows
 
The basic setting method is as described above.

Keywords: Vmware PHP SSL

Added by NoorAdiga on Fri, 12 Jul 2019 23:17:07 +0300