use of com.cloud.agent.api.HostStatsEntry in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method getHostStats.
public HostStatsEntry getHostStats(final Connection conn, final GetHostStatsCommand cmd, final String hostGuid, final long hostId) {
final HostStatsEntry hostStats = new HostStatsEntry(hostId, 0, 0, 0, "host", 0, 0, 0, 0);
// call rrd method with 1
final Object[] rrdData = getRRDData(conn, 1);
if (rrdData == null) {
return null;
}
final Integer numRows = (Integer) rrdData[0];
final Integer numColumns = (Integer) rrdData[1];
final Node legend = (Node) rrdData[2];
final Node dataNode = (Node) rrdData[3];
final NodeList legendChildren = legend.getChildNodes();
for (int col = 0; col < numColumns; col++) {
if (legendChildren == null || legendChildren.item(col) == null) {
continue;
}
final String columnMetadata = getXMLNodeValue(legendChildren.item(col));
if (columnMetadata == null) {
continue;
}
final String[] columnMetadataList = columnMetadata.split(":");
if (columnMetadataList.length != 4) {
continue;
}
final String type = columnMetadataList[1];
final String param = columnMetadataList[3];
if (type.equalsIgnoreCase("host")) {
if (param.matches("pif_eth0_rx")) {
hostStats.setNetworkReadKBs(getDataAverage(dataNode, col, numRows) / 1000);
} else if (param.matches("pif_eth0_tx")) {
hostStats.setNetworkWriteKBs(getDataAverage(dataNode, col, numRows) / 1000);
} else if (param.contains("memory_total_kib")) {
hostStats.setTotalMemoryKBs(getDataAverage(dataNode, col, numRows));
} else if (param.contains("memory_free_kib")) {
hostStats.setFreeMemoryKBs(getDataAverage(dataNode, col, numRows));
} else if (param.matches("cpu_avg")) {
// hostStats.setNumCpus(hostStats.getNumCpus() + 1);
hostStats.setCpuUtilization(hostStats.getCpuUtilization() + getDataAverage(dataNode, col, numRows));
}
/*
* if (param.contains("loadavg")) { hostStats.setAverageLoad((hostStats.getAverageLoad() +
* getDataAverage(dataNode, col, numRows))); }
*/
}
}
return hostStats;
}
use of com.cloud.agent.api.HostStatsEntry in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(GetHostStatsCommand cmd) {
VmwareContext context = getServiceContext();
VmwareHypervisorHost hyperHost = getHyperHost(context);
HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), 0, 0, 0, "host", 0, 0, 0, 0);
Answer answer = new GetHostStatsAnswer(cmd, hostStats);
try {
HostStatsEntry entry = getHyperHostStats(hyperHost);
if (entry != null) {
s_logger.debug(String.format("Host stats response from hypervisor is: [%s].", _gson.toJson(entry)));
entry.setHostId(cmd.getHostId());
answer = new GetHostStatsAnswer(cmd, entry);
}
} catch (Exception e) {
s_logger.error(createLogMessageException(e, cmd), e);
}
if (s_logger.isTraceEnabled()) {
s_logger.trace("GetHostStats Answer: " + _gson.toJson(answer));
}
return answer;
}
use of com.cloud.agent.api.HostStatsEntry in project cloudstack by apache.
the class MockAgentManagerImpl method getHostStatistic.
@Override
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
String hostGuid = cmd.getHostGuid();
MockHost host = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
host = _mockHostDao.findByGuid(hostGuid);
txn.commit();
if (host == null) {
return null;
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to get host " + hostGuid + " due to " + ex.getMessage(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
TransactionLegacy vmtxn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
vmtxn.start();
List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
vmtxn.commit();
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);
} catch (Exception ex) {
vmtxn.rollback();
throw new CloudRuntimeException("Unable to get Vms on host " + host.getGuid() + " due to " + ex.getMessage(), ex);
} finally {
vmtxn.close();
vmtxn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
vmtxn.close();
}
}
use of com.cloud.agent.api.HostStatsEntry in project cloudstack by apache.
the class OvmResourceBase method execute.
protected Answer execute(GetHostStatsCommand cmd) {
try {
Map<String, String> res = OvmHost.getPerformanceStats(_conn, _publicNetworkName);
Double cpuUtil = Double.parseDouble(res.get("cpuUtil"));
Double rxBytes = Double.parseDouble(res.get("rxBytes"));
Double txBytes = Double.parseDouble(res.get("txBytes"));
Double totalMemory = Double.parseDouble(res.get("totalMemory"));
Double freeMemory = Double.parseDouble(res.get("freeMemory"));
HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rxBytes, txBytes, "host", totalMemory, freeMemory, 0, 0);
return new GetHostStatsAnswer(cmd, hostStats);
} catch (Exception e) {
s_logger.debug("Get host stats of " + cmd.getHostName() + " failed", e);
return new Answer(cmd, false, e.getMessage());
}
}
use of com.cloud.agent.api.HostStatsEntry in project cloudstack by apache.
the class CitrixResourceBase method getHostStats.
public HostStatsEntry getHostStats(final Connection conn, final GetHostStatsCommand cmd, final String hostGuid, final long hostId) {
final HostStatsEntry hostStats = new HostStatsEntry(hostId, 0, 0, 0, "host", 0, 0, 0, 0);
// call rrd method with 1
final Object[] rrdData = getRRDData(conn, 1);
if (rrdData == null) {
return null;
}
final Integer numRows = (Integer) rrdData[0];
final Integer numColumns = (Integer) rrdData[1];
final Node legend = (Node) rrdData[2];
final Node dataNode = (Node) rrdData[3];
final NodeList legendChildren = legend.getChildNodes();
for (int col = 0; col < numColumns; col++) {
if (legendChildren == null || legendChildren.item(col) == null) {
continue;
}
final String columnMetadata = getXMLNodeValue(legendChildren.item(col));
if (columnMetadata == null) {
continue;
}
final String[] columnMetadataList = columnMetadata.split(":");
if (columnMetadataList.length != 4) {
continue;
}
final String type = columnMetadataList[1];
final String param = columnMetadataList[3];
if (type.equalsIgnoreCase("host")) {
if (param.matches("pif_eth0_rx")) {
hostStats.setNetworkReadKBs(getDataAverage(dataNode, col, numRows) / 1000);
} else if (param.matches("pif_eth0_tx")) {
hostStats.setNetworkWriteKBs(getDataAverage(dataNode, col, numRows) / 1000);
} else if (param.contains("memory_total_kib")) {
hostStats.setTotalMemoryKBs(getDataAverage(dataNode, col, numRows));
} else if (param.contains("memory_free_kib")) {
hostStats.setFreeMemoryKBs(getDataAverage(dataNode, col, numRows));
} else if (param.matches("cpu_avg")) {
// hostStats.setNumCpus(hostStats.getNumCpus() + 1);
hostStats.setCpuUtilization(hostStats.getCpuUtilization() + getDataAverage(dataNode, col, numRows));
}
/*
* if (param.contains("loadavg")) {
* hostStats.setAverageLoad((hostStats.getAverageLoad() +
* getDataAverage(dataNode, col, numRows))); }
*/
}
}
return hostStats;
}
Aggregations