Search in sources :

Example 1 with HostMetricsResponse

use of org.apache.cloudstack.response.HostMetricsResponse in project cloudstack by apache.

the class MetricsServiceImpl method listHostMetrics.

@Override
public List<HostMetricsResponse> listHostMetrics(List<HostResponse> hostResponses) {
    final List<HostMetricsResponse> metricsResponses = new ArrayList<>();
    for (final HostResponse hostResponse : hostResponses) {
        HostMetricsResponse metricsResponse = new HostMetricsResponse();
        try {
            BeanUtils.copyProperties(metricsResponse, hostResponse);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate host metrics response");
        }
        final Host host = hostDao.findByUuid(hostResponse.getId());
        if (host == null) {
            continue;
        }
        final Long hostId = host.getId();
        final Long clusterId = host.getClusterId();
        // Thresholds
        final Double cpuThreshold = AlertManager.CPUCapacityThreshold.valueIn(clusterId);
        final Double memoryThreshold = AlertManager.MemoryCapacityThreshold.valueIn(clusterId);
        final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.valueIn(clusterId);
        final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.valueIn(clusterId);
        // Over commit ratios
        final Double cpuOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "cpuOvercommitRatio"));
        final Double memoryOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "memoryOvercommitRatio"));
        Long upInstances = 0L;
        Long totalInstances = 0L;
        for (final VMInstanceVO instance : vmInstanceDao.listByHostId(hostId)) {
            if (instance == null) {
                continue;
            }
            if (instance.getType() == VirtualMachine.Type.User) {
                totalInstances++;
                if (instance.getState() == VirtualMachine.State.Running) {
                    upInstances++;
                }
            }
        }
        metricsResponse.setPowerState(hostResponse.getOutOfBandManagementResponse().getPowerState());
        metricsResponse.setInstances(upInstances, totalInstances);
        metricsResponse.setCpuTotal(hostResponse.getCpuNumber(), hostResponse.getCpuSpeed(), cpuOvercommitRatio);
        metricsResponse.setCpuUsed(hostResponse.getCpuUsed(), hostResponse.getCpuNumber(), hostResponse.getCpuSpeed());
        metricsResponse.setCpuAllocated(hostResponse.getCpuAllocated(), hostResponse.getCpuNumber(), hostResponse.getCpuSpeed());
        metricsResponse.setMemTotal(hostResponse.getMemoryTotal(), memoryOvercommitRatio);
        metricsResponse.setMemAllocated(hostResponse.getMemoryAllocated());
        metricsResponse.setMemUsed(hostResponse.getMemoryUsed());
        metricsResponse.setNetworkRead(hostResponse.getNetworkKbsRead());
        metricsResponse.setNetworkWrite(hostResponse.getNetworkKbsWrite());
        // CPU thresholds
        metricsResponse.setCpuUsageThreshold(hostResponse.getCpuUsed(), cpuThreshold);
        metricsResponse.setCpuUsageDisableThreshold(hostResponse.getCpuUsed(), cpuDisableThreshold);
        metricsResponse.setCpuAllocatedThreshold(hostResponse.getCpuAllocated(), cpuOvercommitRatio, cpuThreshold);
        metricsResponse.setCpuAllocatedDisableThreshold(hostResponse.getCpuAllocated(), cpuOvercommitRatio, cpuDisableThreshold);
        // Memory thresholds
        metricsResponse.setMemoryUsageThreshold(hostResponse.getMemoryUsed(), hostResponse.getMemoryTotal(), memoryThreshold);
        metricsResponse.setMemoryUsageDisableThreshold(hostResponse.getMemoryUsed(), hostResponse.getMemoryTotal(), memoryDisableThreshold);
        metricsResponse.setMemoryAllocatedThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryOvercommitRatio, memoryThreshold);
        metricsResponse.setMemoryAllocatedDisableThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryOvercommitRatio, memoryDisableThreshold);
        metricsResponses.add(metricsResponse);
    }
    return metricsResponses;
}
Also used : ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) HostMetricsResponse(org.apache.cloudstack.response.HostMetricsResponse) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerApiException(org.apache.cloudstack.api.ServerApiException) HostResponse(org.apache.cloudstack.api.response.HostResponse)

Aggregations

Host (com.cloud.host.Host)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 HostResponse (org.apache.cloudstack.api.response.HostResponse)1 HostMetricsResponse (org.apache.cloudstack.response.HostMetricsResponse)1