Search in sources :

Example 1 with GetHostStatsAnswer

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

the class MockAgentManagerImpl method getHostStatistic.

@Override
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
    String hostGuid = cmd.getHostGuid();
    MockHost host = _mockHostDao.findByGuid(hostGuid);
    if (host == null) {
        return null;
    }
    List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
    double usedMem = 0.0;
    double usedCpu = 0.0;
    for (MockVMVO vm : vms) {
        usedMem += vm.getMemory();
        usedCpu += vm.getCpu();
    }
    HostStatsEntry hostStats = new HostStatsEntry();
    hostStats.setTotalMemoryKBs(host.getMemorySize());
    hostStats.setFreeMemoryKBs(host.getMemorySize() - usedMem);
    hostStats.setNetworkReadKBs(32768);
    hostStats.setNetworkWriteKBs(16384);
    hostStats.setCpuUtilization(usedCpu / (host.getCpuCount() * host.getCpuSpeed()));
    hostStats.setEntityType("simulator-host");
    hostStats.setHostId(cmd.getHostId());
    return new GetHostStatsAnswer(cmd, hostStats);
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) MockHost(com.cloud.simulator.MockHost) HostStatsEntry(com.cloud.agent.api.HostStatsEntry)

Example 2 with GetHostStatsAnswer

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

the class HypervDirectConnectResourceTest method testGetHostStatsCommand.

@Test
public final void testGetHostStatsCommand() {
    // Arrange
    long hostIdVal = 123;
    GetHostStatsCommand cmd = new GetHostStatsCommand("1", "testHost", hostIdVal);
    // Act
    GetHostStatsAnswer ans = (GetHostStatsAnswer) s_hypervresource.executeRequest(cmd);
    // Assert
    Assert.assertTrue(ans.getResult());
    Assert.assertTrue(0.0 < ans.getTotalMemoryKBs());
    Assert.assertTrue(0.0 < ans.getFreeMemoryKBs());
    Assert.assertTrue(0.0 <= ans.getNetworkReadKBs());
    Assert.assertTrue(0.0 <= ans.getNetworkWriteKBs());
    Assert.assertTrue(0.0 <= ans.getCpuUtilization());
    Assert.assertTrue(100 >= ans.getCpuUtilization());
    Assert.assertTrue(ans.getEntityType().equals("host"));
    Assert.assertTrue(ans.getDetails() == null);
}
Also used : GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) Test(org.junit.Test)

Example 3 with GetHostStatsAnswer

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

the class Ovm3HypervisorSupport method execute.

public Answer execute(GetHostStatsCommand cmd) {
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        Map<String, String> stats = cSp.ovsDom0Stats(config.getAgentPublicNetworkName());
        Double cpuUtil = Double.parseDouble(stats.get("cpu"));
        Double rxBytes = Double.parseDouble(stats.get("rx"));
        Double txBytes = Double.parseDouble(stats.get("tx"));
        Double totalMemory = Double.parseDouble(stats.get("total"));
        Double freeMemory = Double.parseDouble(stats.get("free"));
        HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rxBytes, txBytes, "host", totalMemory, freeMemory, 0, 0);
        return new GetHostStatsAnswer(cmd, hostStats);
    } catch (Exception e) {
        LOGGER.debug("Unable to get host stats for: " + cmd.getHostName(), e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 4 with GetHostStatsAnswer

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

the class LibvirtComputingResource method execute.

private Answer execute(GetHostStatsCommand cmd) {
    final Script cpuScript = new Script("/bin/bash", s_logger);
    cpuScript.add("-c");
    cpuScript.add("idle=$(top -b -n 1|grep Cpu\\(s\\):|cut -d% -f4|cut -d, -f2);echo $idle");
    final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
    String result = cpuScript.execute(parser);
    if (result != null) {
        s_logger.debug("Unable to get the host CPU state: " + result);
        return new Answer(cmd, false, result);
    }
    double cpuUtil = (100.0D - Double.parseDouble(parser.getLine()));
    long freeMem = 0;
    final Script memScript = new Script("/bin/bash", s_logger);
    memScript.add("-c");
    memScript.add("freeMem=$(free|grep cache:|awk '{print $4}');echo $freeMem");
    final OutputInterpreter.OneLineParser Memparser = new OutputInterpreter.OneLineParser();
    result = memScript.execute(Memparser);
    if (result != null) {
        s_logger.debug("Unable to get the host Mem state: " + result);
        return new Answer(cmd, false, result);
    }
    freeMem = Long.parseLong(Memparser.getLine());
    Script totalMem = new Script("/bin/bash", s_logger);
    totalMem.add("-c");
    totalMem.add("free|grep Mem:|awk '{print $2}'");
    final OutputInterpreter.OneLineParser totMemparser = new OutputInterpreter.OneLineParser();
    result = totalMem.execute(totMemparser);
    if (result != null) {
        s_logger.debug("Unable to get the host Mem state: " + result);
        return new Answer(cmd, false, result);
    }
    long totMem = Long.parseLong(totMemparser.getLine());
    Pair<Double, Double> nicStats = getNicStats(_publicBridgeName);
    HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, nicStats.first() / 1000, nicStats.second() / 1000, "host", totMem, freeMem, 0, 0);
    return new GetHostStatsAnswer(cmd, hostStats);
}
Also used : Script(com.cloud.utils.script.Script) FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) OutputInterpreter(com.cloud.utils.script.OutputInterpreter)

Example 5 with GetHostStatsAnswer

use of com.cloud.agent.api.GetHostStatsAnswer 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

GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)11 HostStatsEntry (com.cloud.agent.api.HostStatsEntry)8 Answer (com.cloud.agent.api.Answer)6 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)6 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)4 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)4 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ConfigurationException (javax.naming.ConfigurationException)4 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)3 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)3 FenceAnswer (com.cloud.agent.api.FenceAnswer)3 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)3 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)3 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)3 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)3 PrepareForMigrationAnswer (com.cloud.agent.api.PrepareForMigrationAnswer)3 RebootAnswer (com.cloud.agent.api.RebootAnswer)3 StartAnswer (com.cloud.agent.api.StartAnswer)3