Search in sources :

Example 1 with MemStat

use of com.cloud.utils.linux.MemStat in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testGetHostStatsCommand.

@Test
public void testGetHostStatsCommand() {
    Mockito.mock(LibvirtUtilitiesHelper.class);
    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(Matchers.anyString())).thenReturn(new Pair<>(1.0d, 1.0d));
    when(cpuStat.getCpuUsedPercent()).thenReturn(0.5d);
    when(memStat.getAvailable()).thenReturn(1500.5d);
    when(memStat.getTotal()).thenReturn(15000d);
    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 : Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) CpuStat(com.cloud.utils.linux.CpuStat) MemStat(com.cloud.utils.linux.MemStat) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) Test(org.junit.Test)

Example 2 with MemStat

use of com.cloud.utils.linux.MemStat in project cosmic by MissionCriticalCloud.

the class LibvirtGetHostStatsCommandWrapper method execute.

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

Aggregations

CpuStat (com.cloud.utils.linux.CpuStat)2 MemStat (com.cloud.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 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)1 AttachAnswer (com.cloud.storage.command.AttachAnswer)1 Test (org.junit.Test)1