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);
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations