Search in sources :

Example 1 with CPUStat

use of org.apache.cloudstack.utils.linux.CPUStat in project cloudstack by apache.

the class LibvirtGetHostStatsCommandWrapper method execute.

@Override
public Answer execute(final GetHostStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
    CPUStat cpuStat = libvirtComputingResource.getCPUStat();
    MemStat memStat = libvirtComputingResource.getMemStat();
    final double cpuUtil = cpuStat.getCpuUsedPercent();
    final double loadAvg = cpuStat.getCpuLoadAverage();
    final Pair<Double, Double> nicStats = libvirtComputingResource.getNicStats(libvirtComputingResource.getPublicBridgeName());
    final HostStatsEntry hostStats = new HostStatsEntry(command.getHostId(), cpuUtil, nicStats.first() / 1024, nicStats.second() / 1024, "host", memStat.getTotal() / 1024, memStat.getAvailable() / 1024, 0, loadAvg);
    return new GetHostStatsAnswer(command, hostStats);
}
Also used : GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CPUStat(org.apache.cloudstack.utils.linux.CPUStat) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) MemStat(org.apache.cloudstack.utils.linux.MemStat)

Example 2 with CPUStat

use of org.apache.cloudstack.utils.linux.CPUStat in project cloudstack by apache.

the class LibvirtComputingResourceTest method testGetHostStatsCommand.

@Test
public void testGetHostStatsCommand() {
    // A bit difficult to test due to the logger being passed and the parser itself relying on the connection.
    // Have to spend some more time afterwards in order to refactor the wrapper itself.
    final CPUStat cpuStat = Mockito.mock(CPUStat.class);
    final MemStat memStat = Mockito.mock(MemStat.class);
    final String uuid = "e8d6b4d0-bc6d-4613-b8bb-cb9e0600f3c6";
    final GetHostStatsCommand command = new GetHostStatsCommand(uuid, "summer", 1l);
    when(libvirtComputingResource.getCPUStat()).thenReturn(cpuStat);
    when(libvirtComputingResource.getMemStat()).thenReturn(memStat);
    when(libvirtComputingResource.getNicStats(nullable(String.class))).thenReturn(new Pair<Double, Double>(1.0d, 1.0d));
    when(cpuStat.getCpuUsedPercent()).thenReturn(0.5d);
    when(memStat.getAvailable()).thenReturn(1500L);
    when(memStat.getTotal()).thenReturn(15000L);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getCPUStat();
    verify(libvirtComputingResource, times(1)).getMemStat();
    verify(cpuStat, times(1)).getCpuUsedPercent();
    verify(memStat, times(1)).getAvailable();
    verify(memStat, times(1)).getTotal();
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) CPUStat(org.apache.cloudstack.utils.linux.CPUStat) MemStat(org.apache.cloudstack.utils.linux.MemStat) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CPUStat (org.apache.cloudstack.utils.linux.CPUStat)2 MemStat (org.apache.cloudstack.utils.linux.MemStat)2 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)1 HostStatsEntry (com.cloud.agent.api.HostStatsEntry)1 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)1 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)1 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1