use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin 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.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3VirtualRoutingSupport method execute.
public CheckSshAnswer execute(CheckSshCommand cmd) {
String vmName = cmd.getName();
String privateIp = cmd.getIp();
int cmdPort = cmd.getPort();
int interval = cmd.getInterval();
int retries = cmd.getRetries();
try {
CloudstackPlugin cSp = new CloudstackPlugin(c);
if (!cSp.dom0CheckPort(privateIp, cmdPort, retries, interval)) {
String msg = "Port " + cmdPort + " not reachable for " + vmName + ": " + config.getAgentHostname();
LOGGER.info(msg);
return new CheckSshAnswer(cmd, msg);
}
} catch (Exception e) {
String msg = "Can not reach port " + cmdPort + " on System vm " + vmName + ": " + config.getAgentHostname() + " due to exception: " + e;
LOGGER.error(msg);
return new CheckSshAnswer(cmd, msg);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ping " + cmdPort + " succeeded for vm " + vmName + ": " + config.getAgentHostname() + " " + cmd);
}
return new CheckSshAnswer(cmd);
}
use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3VmSupport method getVmStat.
private VmStatsEntry getVmStat(String vmName) {
CloudstackPlugin cSp = new CloudstackPlugin(c);
Map<String, String> oldVmStats = null;
Map<String, String> newVmStats = null;
VmStatsEntry stats = new VmStatsEntry();
try {
if (vmStats.containsKey(vmName)) {
oldVmStats = new HashMap<String, String>();
oldVmStats.putAll(vmStats.get(vmName));
}
newVmStats = cSp.ovsDomUStats(vmName);
} catch (Ovm3ResourceException e) {
LOGGER.info("Unable to retrieve stats from " + vmName, e);
return stats;
}
if (oldVmStats == null) {
LOGGER.debug("No old stats retrieved stats from " + vmName);
stats.setNumCPUs(1);
stats.setNetworkReadKBs(0);
stats.setNetworkWriteKBs(0);
stats.setDiskReadKBs(0);
stats.setDiskWriteKBs(0);
stats.setDiskReadIOs(0);
stats.setDiskWriteIOs(0);
stats.setCPUUtilization(0);
stats.setEntityType("vm");
} else {
LOGGER.debug("Retrieved new stats from " + vmName);
int cpus = Integer.parseInt(newVmStats.get("vcpus"));
stats.setNumCPUs(cpus);
stats.setNetworkReadKBs(doubleMin(newVmStats.get("rx_bytes"), oldVmStats.get("rx_bytes")));
stats.setNetworkWriteKBs(doubleMin(newVmStats.get("tx_bytes"), oldVmStats.get("tx_bytes")));
stats.setDiskReadKBs(doubleMin(newVmStats.get("rd_bytes"), oldVmStats.get("rd_bytes")));
stats.setDiskWriteKBs(doubleMin(newVmStats.get("rw_bytes"), oldVmStats.get("rw_bytes")));
stats.setDiskReadIOs(doubleMin(newVmStats.get("rd_ops"), oldVmStats.get("rd_ops")));
stats.setDiskWriteIOs(doubleMin(newVmStats.get("rw_ops"), oldVmStats.get("rw_ops")));
Double dCpu = doubleMin(newVmStats.get("cputime"), oldVmStats.get("cputime"));
Double dTime = doubleMin(newVmStats.get("uptime"), oldVmStats.get("uptime"));
Double cpupct = dCpu / dTime * 100 * cpus;
stats.setCPUUtilization(cpupct);
stats.setEntityType("vm");
}
((ConcurrentHashMap<String, Map<String, String>>) vmStats).put(vmName, newVmStats);
return stats;
}
use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3HypervisorSupport method execute.
/* check "the" virtual machine */
public CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
LOGGER.debug("CheckVirtualMachineCommand: " + cmd.getVmName());
String vmName = cmd.getVmName();
try {
CloudstackPlugin plug = new CloudstackPlugin(c);
Integer vncPort = Integer.valueOf(plug.getVncPort(vmName));
if (vncPort == 0) {
LOGGER.warn("No VNC port for " + vmName);
}
/* we already have the state ftw */
Map<String, State> states = getAllVmStates(vmStateMap);
State vmState = states.get(vmName);
if (vmState == null) {
LOGGER.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand");
vmState = State.Stopped;
}
synchronized (vmStateMap) {
vmStateMap.put(vmName, State.Running);
}
return new CheckVirtualMachineAnswer(cmd, convertStateToPower(vmState), vncPort);
} catch (Ovm3ResourceException e) {
LOGGER.debug("Check migration for " + vmName + " failed", e);
return new CheckVirtualMachineAnswer(cmd, convertStateToPower(State.Stopped), null);
}
}
use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.
the class Ovm3HypervisorSupport method execute.
public CheckOnHostAnswer execute(CheckOnHostCommand cmd) {
LOGGER.debug("CheckOnHostCommand");
CloudstackPlugin csp = new CloudstackPlugin(c);
try {
Boolean alive = csp.dom0CheckStorageHealth(config.getAgentScriptsDir(), config.getAgentCheckStorageScript(), cmd.getHost().getGuid(), config.getAgentStorageCheckTimeout());
String msg = "";
if (alive == null) {
msg = "storage check failed for " + cmd.getHost().getGuid();
} else if (alive) {
msg = "storage check ok for " + cmd.getHost().getGuid();
} else {
msg = "storage dead for " + cmd.getHost().getGuid();
}
LOGGER.debug(msg);
return new CheckOnHostAnswer(cmd, alive, msg);
} catch (Ovm3ResourceException e) {
return new CheckOnHostAnswer(cmd, false, "Error while checking storage for " + cmd.getHost().getGuid() + ": " + e.getMessage());
}
}
Aggregations