Search in sources :

Example 1 with ZoneMetricsResponse

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

the class MetricsServiceImpl method listZoneMetrics.

@Override
public List<ZoneMetricsResponse> listZoneMetrics(List<ZoneResponse> zoneResponses) {
    final List<ZoneMetricsResponse> metricsResponses = new ArrayList<>();
    for (final ZoneResponse zoneResponse : zoneResponses) {
        ZoneMetricsResponse metricsResponse = new ZoneMetricsResponse();
        try {
            BeanUtils.copyProperties(metricsResponse, zoneResponse);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate zone metrics response");
        }
        final DataCenter zone = dataCenterDao.findByUuid(zoneResponse.getId());
        if (zone == null) {
            continue;
        }
        final Long zoneId = zone.getId();
        // Thresholds
        final Double cpuThreshold = AlertManager.CPUCapacityThreshold.value();
        final Double memoryThreshold = AlertManager.MemoryCapacityThreshold.value();
        final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.value();
        final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.value();
        // CPU and memory capacities
        final CapacityDaoImpl.SummedCapacity cpuCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_CPU, zoneId, null);
        final CapacityDaoImpl.SummedCapacity memoryCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, zoneId, null);
        final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity);
        for (final Cluster cluster : clusterDao.listClustersByDcId(zoneId)) {
            metrics.incrTotalResources();
            if (cluster.getAllocationState() == Grouping.AllocationState.Enabled && cluster.getManagedState() == Managed.ManagedState.Managed) {
                metrics.incrUpResources();
            }
            for (final HostJoinVO host : hostJoinDao.findByClusterId(cluster.getId(), Host.Type.Routing)) {
                updateHostMetrics(metrics, host);
            }
        }
        metricsResponse.setState(zoneResponse.getAllocationState());
        metricsResponse.setResource(metrics.getUpResources(), metrics.getTotalResources());
        // CPU
        metricsResponse.setCpuTotal(metrics.getTotalCpu());
        metricsResponse.setCpuAllocated(metrics.getCpuAllocated(), metrics.getTotalCpu());
        if (metrics.getCpuUsedPercentage() > 0L) {
            metricsResponse.setCpuUsed(metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
            metricsResponse.setCpuMaxDeviation(metrics.getMaximumCpuUsage(), metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
        }
        // Memory
        metricsResponse.setMemTotal(metrics.getTotalMemory());
        metricsResponse.setMemAllocated(metrics.getMemoryAllocated(), metrics.getTotalMemory());
        if (metrics.getMemoryUsed() > 0L) {
            metricsResponse.setMemUsed(metrics.getMemoryUsed(), metrics.getTotalMemory());
            metricsResponse.setMemMaxDeviation(metrics.getMaximumMemoryUsage(), metrics.getMemoryUsed(), metrics.getTotalHosts());
        }
        // CPU thresholds
        metricsResponse.setCpuUsageThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuThreshold);
        metricsResponse.setCpuUsageDisableThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuDisableThreshold);
        metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuThreshold);
        metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuDisableThreshold);
        // Memory thresholds
        metricsResponse.setMemoryUsageThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryThreshold);
        metricsResponse.setMemoryUsageDisableThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryDisableThreshold);
        metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryThreshold);
        metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryDisableThreshold);
        metricsResponses.add(metricsResponse);
    }
    return metricsResponses;
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.cloud.org.Cluster) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) InvocationTargetException(java.lang.reflect.InvocationTargetException) ZoneResponse(org.apache.cloudstack.api.response.ZoneResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException) ZoneMetricsResponse(org.apache.cloudstack.response.ZoneMetricsResponse) CapacityDaoImpl(com.cloud.capacity.dao.CapacityDaoImpl)

Aggregations

HostJoinVO (com.cloud.api.query.vo.HostJoinVO)1 CapacityDaoImpl (com.cloud.capacity.dao.CapacityDaoImpl)1 DataCenter (com.cloud.dc.DataCenter)1 Cluster (com.cloud.org.Cluster)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ZoneResponse (org.apache.cloudstack.api.response.ZoneResponse)1 ZoneMetricsResponse (org.apache.cloudstack.response.ZoneMetricsResponse)1