Ejemplo n.º 1
0
def update_data():
	"""Update snmp's data from cxm API"""
	global pp
	global node
	global nr_cpu

	# Load all stats once
	vms=node.get_vms()
	ram=node.metrics.get_ram_infos()
	vgs_io=node.metrics.get_host_vgs_io()
	net_io=node.metrics.get_host_net_io()
	vms_stat=node.metrics.get_vms_record()

	# Node infos
	pp.add_str('1.1.0',node.get_hostname())
	pp.add_gau('1.2.0',nr_cpu)

	# Number of VM
	pp.add_gau('1.3.0',len(vms))

	# Number of used IRQ
	pp.add_gau('1.4.0',node.metrics.get_used_irq())

	# Ram infos
	pp.add_gau('1.5.1.0',ram['used'])
	pp.add_gau('1.5.2.0',ram['free'])

	# Disk's IO
	for name in vgs_io.keys():
		oid=pp.encode(name)
		pp.add_str('1.6.1.'+oid,name)
		pp.add_cnt_32bit('1.6.2.'+oid,vgs_io[name]['Read'])
		pp.add_cnt_32bit('1.6.3.'+oid,vgs_io[name]['Write'])

	# Network's IO
	for name in net_io['bridges'].keys():
		oid=pp.encode(name)
		pp.add_str('1.7.1.'+oid,name)
		pp.add_cnt_32bit('1.7.2.'+oid,net_io['bridges'][name]['Rx'])
		pp.add_cnt_32bit('1.7.3.'+oid,net_io['bridges'][name]['Tx'])

	for name in net_io['vlans'].keys():
		oid=pp.encode(name)
		pp.add_str('1.8.1.'+oid,name)
		pp.add_cnt_32bit('1.8.2.'+oid,net_io['vlans'][name]['Rx'])
		pp.add_cnt_32bit('1.8.3.'+oid,net_io['vlans'][name]['Tx'])

	# For each VM
	for vm in vms:
		oid=pp.encode(vm.name)
		pp.add_str('1.9.1.'+oid,vm.name)
		pp.add_int('1.9.2.'+oid,vm.id)
		pp.add_gau('1.9.4.'+oid,vm.get_vcpu())
		pp.add_gau('1.9.5.'+oid,vm.get_ram())

		try:
			# CPU Percentage relative to the host capacity and *100 to pass decimal through snmpd
			pp.add_gau('1.9.3.'+oid,"%d" % (round(vms_stat[vm.name]['cpu']/nr_cpu,2)*100)) 
			pp.add_cnt_32bit('1.9.6.'+oid,vms_stat[vm.name]['disk']['Read'])
			pp.add_cnt_32bit('1.9.7.'+oid,vms_stat[vm.name]['disk']['Write'])
			pp.add_cnt_32bit('1.9.8.'+oid,sum([ vif['Rx'] for vif in vms_stat[vm.name]['net'] ]))
			pp.add_cnt_32bit('1.9.9.'+oid,sum([ vif['Tx'] for vif in vms_stat[vm.name]['net'] ]))
		except KeyError, TypeError:
			# If a VM has disappeared
			continue
Ejemplo n.º 2
0
def update_data():
	"""Update snmp's data from cxm API"""
	global pp
	global node

	# Load all stats once
	vms=node.get_vms()
	ram=node.metrics.get_ram_infos()
	nr_cpu=int(node.metrics.get_host_nr_cpus())
	vgs_io=node.metrics.get_host_vgs_io()
	net_io=node.metrics.get_host_net_io()
	vms_stat=node.metrics.get_vms_record()

	# Number of VM
	pp.add_gau('1.3.0',len(vms))

	# Number of used IRQ
	pp.add_gau('1.4.0',node.metrics.get_used_irq())

	# Ram infos
	pp.add_gau('1.5.1.0',ram['used'])
	pp.add_gau('1.5.2.0',ram['free'])

	# Disk's IO
	for name in vgs_io.keys():
		oid=pp.encode(name)
		pp.add_str('1.6.1.'+oid,name)
		pp.add_cnt('1.6.2.'+oid,vgs_io[name]['Read'])
		pp.add_cnt('1.6.3.'+oid,vgs_io[name]['Write'])

	# Network's IO
	for name in net_io['bridges'].keys():
		oid=pp.encode(name)
		pp.add_str('1.7.1.'+oid,name)
		pp.add_cnt('1.7.2.'+oid,net_io['bridges'][name]['Rx'])
		pp.add_cnt('1.7.3.'+oid,net_io['bridges'][name]['Tx'])

	for name in net_io['vlans'].keys():
		oid=pp.encode(name)
		pp.add_str('1.8.1.'+oid,name)
		pp.add_cnt('1.8.2.'+oid,net_io['vlans'][name]['Rx'])
		pp.add_cnt('1.8.3.'+oid,net_io['vlans'][name]['Tx'])

	# For each VM
	for vm in vms:
		oid=pp.encode(vm.name)
		pp.add_str('1.9.1.'+oid,vm.name)
		pp.add_int('1.9.2.'+oid,vm.id)
		pp.add_gau('1.9.3.'+oid,"%.1f" % round(vms_stat[vm.name]['cpu']/nr_cpu,1)) # CPU Percentage relative to the host capatity
		pp.add_gau('1.9.4.'+oid,vm.get_vcpu())
		pp.add_gau('1.9.5.'+oid,vm.get_ram())
		pp.add_cnt('1.9.6.'+oid,vms_stat[vm.name]['disk']['Read'])
		pp.add_cnt('1.9.7.'+oid,vms_stat[vm.name]['disk']['Write'])
		vifn=0
		for vif in vms_stat[vm.name]['net']:
			vifoid=pp.encode('eth'+str(vifn))
			pp.add_str('1.10.1.'+vifoid+'.'+oid,'eth'+str(vifn))
			pp.add_cnt('1.10.2.'+vifoid+'.'+oid,vif['Rx'])
			pp.add_cnt('1.10.3.'+vifoid+'.'+oid,vif['Tx'])
			vifn+=1

	# For the dom0
	oid=pp.encode("Domain-0")
	pp.add_gau('1.9.3.'+oid,"%.1f" % round(vms_stat['Domain-0']['cpu']/nr_cpu,1))
Ejemplo n.º 3
0
def update_data():
    """Update snmp's data from cxm API"""
    global pp
    global node

    # Load all stats once
    vms = node.get_vms()
    ram = node.metrics.get_ram_infos()
    nr_cpu = int(node.metrics.get_host_nr_cpus())
    vgs_io = node.metrics.get_host_vgs_io()
    net_io = node.metrics.get_host_net_io()
    vms_stat = node.metrics.get_vms_record()

    # Number of VM
    pp.add_gau('1.3.0', len(vms))

    # Number of used IRQ
    pp.add_gau('1.4.0', node.metrics.get_used_irq())

    # Ram infos
    pp.add_gau('1.5.1.0', ram['used'])
    pp.add_gau('1.5.2.0', ram['free'])

    # Disk's IO
    for name in vgs_io.keys():
        oid = pp.encode(name)
        pp.add_str('1.6.1.' + oid, name)
        pp.add_cnt('1.6.2.' + oid, vgs_io[name]['Read'])
        pp.add_cnt('1.6.3.' + oid, vgs_io[name]['Write'])

    # Network's IO
    for name in net_io['bridges'].keys():
        oid = pp.encode(name)
        pp.add_str('1.7.1.' + oid, name)
        pp.add_cnt('1.7.2.' + oid, net_io['bridges'][name]['Rx'])
        pp.add_cnt('1.7.3.' + oid, net_io['bridges'][name]['Tx'])

    for name in net_io['vlans'].keys():
        oid = pp.encode(name)
        pp.add_str('1.8.1.' + oid, name)
        pp.add_cnt('1.8.2.' + oid, net_io['vlans'][name]['Rx'])
        pp.add_cnt('1.8.3.' + oid, net_io['vlans'][name]['Tx'])

    # For each VM
    for vm in vms:
        oid = pp.encode(vm.name)
        pp.add_str('1.9.1.' + oid, vm.name)
        pp.add_int('1.9.2.' + oid, vm.id)
        pp.add_gau('1.9.3.' + oid, "%.1f" %
                   round(vms_stat[vm.name]['cpu'] / nr_cpu,
                         1))  # CPU Percentage relative to the host capatity
        pp.add_gau('1.9.4.' + oid, vm.get_vcpu())
        pp.add_gau('1.9.5.' + oid, vm.get_ram())
        pp.add_cnt('1.9.6.' + oid, vms_stat[vm.name]['disk']['Read'])
        pp.add_cnt('1.9.7.' + oid, vms_stat[vm.name]['disk']['Write'])
        vifn = 0
        for vif in vms_stat[vm.name]['net']:
            vifoid = pp.encode('eth' + str(vifn))
            pp.add_str('1.10.1.' + vifoid + '.' + oid, 'eth' + str(vifn))
            pp.add_cnt('1.10.2.' + vifoid + '.' + oid, vif['Rx'])
            pp.add_cnt('1.10.3.' + vifoid + '.' + oid, vif['Tx'])
            vifn += 1

    # For the dom0
    oid = pp.encode("Domain-0")
    pp.add_gau('1.9.3.' + oid,
               "%.1f" % round(vms_stat['Domain-0']['cpu'] / nr_cpu, 1))