mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
1) Add HostStats support to vmwre
2) Normarlize HostStats to make it generic to all hypervisors
This commit is contained in:
parent
04f39a7da7
commit
1805c73363
@ -2139,7 +2139,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||
|
||||
}
|
||||
|
||||
HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rx, tx, numCpus, "host", totMem, freeMem, 0, 0);
|
||||
HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rx, tx, "host", totMem, freeMem, 0, 0);
|
||||
return new GetHostStatsAnswer(cmd, hostStats);
|
||||
}
|
||||
|
||||
|
||||
@ -17,8 +17,6 @@
|
||||
*/
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.cloud.host.HostStats;
|
||||
|
||||
/**
|
||||
@ -28,18 +26,9 @@ import com.cloud.host.HostStats;
|
||||
public class GetHostStatsAnswer extends Answer implements HostStats {
|
||||
|
||||
HostStatsEntry hostStats;
|
||||
|
||||
double cpuUtilization;
|
||||
double networkReadKBs;
|
||||
double networkWriteKBs;
|
||||
int numCPUs;
|
||||
String entityType;
|
||||
double totalMemoryKBs;
|
||||
double freeMemoryKBs;
|
||||
double xapiMemoryUsageKBs;
|
||||
double averageLoad;
|
||||
|
||||
|
||||
protected GetHostStatsAnswer() {
|
||||
hostStats = new HostStatsEntry();
|
||||
}
|
||||
|
||||
public GetHostStatsAnswer(GetHostStatsCommand cmd, HostStatsEntry hostStatistics) {
|
||||
@ -48,67 +37,51 @@ public class GetHostStatsAnswer extends Answer implements HostStats {
|
||||
}
|
||||
|
||||
public GetHostStatsAnswer(GetHostStatsCommand cmd, double cpuUtilization, double freeMemoryKBs, double totalMemoryKBs, double networkReadKBs,
|
||||
double networkWriteKBs, String entityType, double xapiMemoryUsageKBs, double averageLoad, int numCPUs) {
|
||||
double networkWriteKBs, String entityType) {
|
||||
super(cmd);
|
||||
|
||||
this.cpuUtilization = cpuUtilization;
|
||||
this.freeMemoryKBs = freeMemoryKBs;
|
||||
this.totalMemoryKBs = totalMemoryKBs;
|
||||
this.networkReadKBs = networkReadKBs;
|
||||
this.networkWriteKBs = networkWriteKBs;
|
||||
this.entityType = entityType;
|
||||
this.xapiMemoryUsageKBs = xapiMemoryUsageKBs;
|
||||
this.numCPUs = numCPUs;
|
||||
hostStats = new HostStatsEntry();
|
||||
|
||||
hostStats.setCpuUtilization(cpuUtilization);
|
||||
hostStats.setFreeMemoryKBs(freeMemoryKBs);
|
||||
hostStats.setTotalMemoryKBs(totalMemoryKBs);
|
||||
hostStats.setNetworkReadKBs(networkReadKBs);
|
||||
hostStats.setNetworkWriteKBs(networkWriteKBs);
|
||||
hostStats.setEntityType(entityType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getUsedMemory() {
|
||||
return (totalMemoryKBs - freeMemoryKBs);
|
||||
return hostStats.getUsedMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getFreeMemoryKBs() {
|
||||
return freeMemoryKBs;
|
||||
return hostStats.getFreeMemoryKBs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTotalMemoryKBs() {
|
||||
return totalMemoryKBs;
|
||||
return hostStats.getTotalMemoryKBs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCpuUtilization() {
|
||||
return cpuUtilization;
|
||||
return hostStats.getCpuUtilization();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNetworkReadKBs() {
|
||||
return networkReadKBs;
|
||||
return hostStats.getNetworkReadKBs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNetworkWriteKBs() {
|
||||
return networkWriteKBs;
|
||||
return hostStats.getNetworkWriteKBs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAverageLoad() {
|
||||
return averageLoad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getXapiMemoryUsageKBs() {
|
||||
return xapiMemoryUsageKBs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumCpus(){
|
||||
return numCPUs;
|
||||
return hostStats.getEntityType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -26,43 +26,28 @@ import com.cloud.host.HostStats;
|
||||
public class HostStatsEntry implements HostStats {
|
||||
|
||||
long hostId;
|
||||
String entityType;
|
||||
double cpuUtilization;
|
||||
double networkReadKBs;
|
||||
double networkWriteKBs;
|
||||
int numCpus;
|
||||
String entityType;
|
||||
double totalMemoryKBs;
|
||||
double freeMemoryKBs;
|
||||
double xapiMemoryUsageKBs;
|
||||
double averageLoad;
|
||||
|
||||
public HostStatsEntry() {
|
||||
}
|
||||
|
||||
public HostStatsEntry(long hostId,double cpuUtilization, double networkReadKBs, double networkWriteKBs, int numCPUs, String entityType,
|
||||
double totalMemoryKBs, double freeMemoryKBs, double xapiMemoryUsageKBs, double averageLoad)
|
||||
public HostStatsEntry(long hostId,double cpuUtilization, double networkReadKBs, double networkWriteKBs, String entityType,
|
||||
double totalMemoryKBs, double freeMemoryKBs, double xapiMemoryUsageKBs, double averageLoad)
|
||||
{
|
||||
this.hostId = hostId;
|
||||
this.entityType = entityType;
|
||||
this.cpuUtilization = cpuUtilization;
|
||||
this.networkReadKBs = networkReadKBs;
|
||||
this.networkWriteKBs = networkWriteKBs;
|
||||
this.numCpus = numCPUs;
|
||||
this.entityType = entityType;
|
||||
this.totalMemoryKBs = totalMemoryKBs;
|
||||
this.freeMemoryKBs = freeMemoryKBs;
|
||||
this.xapiMemoryUsageKBs = xapiMemoryUsageKBs;
|
||||
this.averageLoad = averageLoad;
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAverageLoad() {
|
||||
return averageLoad;
|
||||
}
|
||||
|
||||
public void setAverageLoad(double averageLoad) {
|
||||
this.averageLoad = averageLoad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNetworkReadKBs() {
|
||||
return networkReadKBs;
|
||||
@ -80,10 +65,6 @@ public class HostStatsEntry implements HostStats {
|
||||
public void setNetworkWriteKBs(double networkWriteKBs) {
|
||||
this.networkWriteKBs = networkWriteKBs;
|
||||
}
|
||||
|
||||
public void setNumCpus(int numCpus) {
|
||||
this.numCpus = numCpus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityType(){
|
||||
@ -112,15 +93,6 @@ public class HostStatsEntry implements HostStats {
|
||||
this.freeMemoryKBs = freeMemoryKBs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getXapiMemoryUsageKBs(){
|
||||
return this.xapiMemoryUsageKBs;
|
||||
}
|
||||
|
||||
public void setXapiMemoryUsageKBs(double xapiMemoryUsageKBs){
|
||||
this.xapiMemoryUsageKBs = xapiMemoryUsageKBs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCpuUtilization() {
|
||||
return this.cpuUtilization;
|
||||
@ -135,14 +107,12 @@ public class HostStatsEntry implements HostStats {
|
||||
return (totalMemoryKBs-freeMemoryKBs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumCpus() {
|
||||
return numCpus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostStats getHostStats() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setHostId(long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,16 +23,16 @@ package com.cloud.host;
|
||||
*/
|
||||
public interface HostStats {
|
||||
|
||||
//host related stats
|
||||
public double getAverageLoad();
|
||||
// host related stats
|
||||
public double getCpuUtilization();
|
||||
public double getNetworkWriteKBs();
|
||||
public double getTotalMemoryKBs();
|
||||
public double getFreeMemoryKBs();
|
||||
public double getXapiMemoryUsageKBs();
|
||||
public double getNetworkReadKBs();
|
||||
public String getEntityType();
|
||||
public double getUsedMemory();
|
||||
public int getNumCpus();
|
||||
public HostStats getHostStats();
|
||||
|
||||
// public double getAverageLoad();
|
||||
// public double getXapiMemoryUsageKBs();
|
||||
}
|
||||
|
||||
@ -1395,7 +1395,7 @@ public abstract class CitrixResourceBase implements ServerResource {
|
||||
|
||||
protected HostStatsEntry getHostStats(Connection conn, GetHostStatsCommand cmd, String hostGuid, long hostId) {
|
||||
|
||||
HostStatsEntry hostStats = new HostStatsEntry(hostId, 0, 0, 0, 0, "host", 0, 0, 0, 0);
|
||||
HostStatsEntry hostStats = new HostStatsEntry(hostId, 0, 0, 0, "host", 0, 0, 0, 0);
|
||||
Object[] rrdData = getRRDData(conn, 1); // call rrd method with 1 for host
|
||||
|
||||
if (rrdData == null) {
|
||||
@ -1448,21 +1448,25 @@ public abstract class CitrixResourceBase implements ServerResource {
|
||||
}
|
||||
|
||||
if (param.contains("cpu")) {
|
||||
hostStats.setNumCpus(hostStats.getNumCpus() + 1);
|
||||
// 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)));
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// add the host cpu utilization
|
||||
/*
|
||||
if (hostStats.getNumCpus() != 0) {
|
||||
hostStats.setCpuUtilization(hostStats.getCpuUtilization() / hostStats.getNumCpus());
|
||||
s_logger.debug("Host cpu utilization " + hostStats.getCpuUtilization());
|
||||
}
|
||||
*/
|
||||
|
||||
return hostStats;
|
||||
}
|
||||
|
||||
@ -502,7 +502,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
float cpuUtil = (float) hostStats.getCpuUtilization();
|
||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
hostResponse.setCpuUsed(cpuUsed);
|
||||
hostResponse.setAverageLoad(Double.doubleToLongBits(hostStats.getAverageLoad()));
|
||||
// hostResponse.setAverageLoad(Double.doubleToLongBits(hostStats.getAverageLoad()));
|
||||
hostResponse.setNetworkKbsRead(Double.doubleToLongBits(hostStats.getNetworkReadKBs()));
|
||||
hostResponse.setNetworkKbsWrite(Double.doubleToLongBits(hostStats.getNetworkWriteKBs()));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user