Search in sources :

Example 6 with VmStatsEntry

use of com.cloud.agent.api.VmStatsEntry in project cloudstack by apache.

the class Ovm3VmSupport method execute.

public GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
    List<String> vmNames = cmd.getVmNames();
    Map<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
    for (String vmName : vmNames) {
        VmStatsEntry e = getVmStat(vmName);
        vmStatsNameMap.put(vmName, e);
    }
    return new GetVmStatsAnswer(cmd, (HashMap<String, VmStatsEntry>) vmStatsNameMap);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 7 with VmStatsEntry

use of com.cloud.agent.api.VmStatsEntry in project CloudStack-archive by CloudStack-extras.

the class MockVmManagerImpl method getVmStats.

@Override
public Answer getVmStats(GetVmStatsCommand cmd) {
    HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
    List<String> vmNames = cmd.getVmNames();
    for (String vmName : vmNames) {
        VmStatsEntry entry = new VmStatsEntry(0, 0, 0, 0, "vm");
        // default values 256 KBps
        entry.setNetworkReadKBs(32768);
        entry.setNetworkWriteKBs(16384);
        entry.setCPUUtilization(10);
        entry.setNumCPUs(1);
        vmStatsNameMap.put(vmName, entry);
    }
    return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 8 with VmStatsEntry

use of com.cloud.agent.api.VmStatsEntry in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
    List<String> vmNames = cmd.getVmNames();
    try {
        HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
        Connect conn = LibvirtConnection.getConnection();
        for (String vmName : vmNames) {
            VmStatsEntry statEntry = getVmStat(conn, vmName);
            if (statEntry == null) {
                continue;
            }
            vmStatsNameMap.put(vmName, statEntry);
        }
        return new GetVmStatsAnswer(cmd, vmStatsNameMap);
    } catch (LibvirtException e) {
        s_logger.debug("Can't get vm stats: " + e.toString());
        return new GetVmStatsAnswer(cmd, null);
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Connect(org.libvirt.Connect) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 9 with VmStatsEntry

use of com.cloud.agent.api.VmStatsEntry in project cloudstack by apache.

the class LibvirtGetVmStatsCommandWrapper method execute.

@Override
public Answer execute(final GetVmStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final List<String> vmNames = command.getVmNames();
    try {
        final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
        for (final String vmName : vmNames) {
            final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
            final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName);
            try {
                final VmStatsEntry statEntry = libvirtComputingResource.getVmStat(conn, vmName);
                if (statEntry == null) {
                    continue;
                }
                vmStatsNameMap.put(vmName, statEntry);
            } catch (LibvirtException e) {
                s_logger.warn("Can't get vm stats: " + e.toString() + ", continue");
            }
        }
        return new GetVmStatsAnswer(command, vmStatsNameMap);
    } catch (final LibvirtException e) {
        s_logger.debug("Can't get vm stats: " + e.toString());
        return new GetVmStatsAnswer(command, null);
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) HashMap(java.util.HashMap) Connect(org.libvirt.Connect) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer)

Example 10 with VmStatsEntry

use of com.cloud.agent.api.VmStatsEntry in project cloudstack by apache.

the class OvmResourceBase method getVmStat.

private VmStatsEntry getVmStat(String vmName) throws XmlRpcException {
    Map<String, String> vmStat = OvmVm.getVmStats(_conn, vmName);
    int nvcpus = Integer.parseInt(vmStat.get("cpuNum"));
    float cpuUtil = Float.parseFloat(vmStat.get("cpuUtil"));
    long rxBytes = Long.parseLong(vmStat.get("rxBytes"));
    long txBytes = Long.parseLong(vmStat.get("txBytes"));
    Pair<Long, Long> oldNetworkStat = _vmNetworkStats.get(vmName);
    long rx = rxBytes;
    long tx = txBytes;
    if (oldNetworkStat != null) {
        rx -= oldNetworkStat.first();
        tx -= oldNetworkStat.second();
        oldNetworkStat.set(rxBytes, txBytes);
    } else {
        oldNetworkStat = new Pair<Long, Long>(rx, tx);
    }
    _vmNetworkStats.put(vmName, oldNetworkStat);
    VmStatsEntry e = new VmStatsEntry();
    e.setCPUUtilization(cpuUtil);
    e.setNumCPUs(nvcpus);
    e.setNetworkReadKBs(rx);
    e.setNetworkWriteKBs(tx);
    e.setEntityType("vm");
    return e;
}
Also used : VmStatsEntry(com.cloud.agent.api.VmStatsEntry)

Aggregations

VmStatsEntry (com.cloud.agent.api.VmStatsEntry)16 HashMap (java.util.HashMap)10 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 ArrayList (java.util.ArrayList)4 Connect (org.libvirt.Connect)3 Answer (com.cloud.agent.api.Answer)2 GetVmDiskStatsAnswer (com.cloud.agent.api.GetVmDiskStatsAnswer)2 StartAnswer (com.cloud.agent.api.StartAnswer)2 Map (java.util.Map)2 Domain (org.libvirt.Domain)2 DomainInfo (org.libvirt.DomainInfo)2 DomainInterfaceStats (org.libvirt.DomainInterfaceStats)2 LibvirtException (org.libvirt.LibvirtException)2 NodeInfo (org.libvirt.NodeInfo)2 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)1 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1