DaanHoogland commented on a change in pull request #5588:
URL: https://github.com/apache/cloudstack/pull/5588#discussion_r782326772
##########
File path:
plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java
##########
@@ -335,61 +362,144 @@ public InfrastructureResponse listInfrastructure() {
}
final Long clusterId = cluster.getId();
- // 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);
-
// CPU and memory capacities
final CapacityDaoImpl.SummedCapacity cpuCapacity =
getCapacity((int) Capacity.CAPACITY_TYPE_CPU, null, clusterId);
final CapacityDaoImpl.SummedCapacity memoryCapacity =
getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, null, clusterId);
- final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity);
+ final HostMetrics hostMetrics = new HostMetrics(cpuCapacity,
memoryCapacity);
for (final Host host: hostDao.findByClusterId(clusterId)) {
if (host == null || host.getType() != Host.Type.Routing) {
continue;
}
if (host.getStatus() == Status.Up) {
- metrics.incrUpResources();
+ hostMetrics.incrUpResources();
}
- metrics.incrTotalResources();
- updateHostMetrics(metrics, hostJoinDao.findById(host.getId()));
+ hostMetrics.incrTotalResources();
+ updateHostMetrics(hostMetrics,
hostJoinDao.findById(host.getId()));
}
metricsResponse.setState(clusterResponse.getAllocationState(),
clusterResponse.getManagedState());
- metricsResponse.setResources(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());
+ metricsResponse.setResources(hostMetrics.getUpResources(),
hostMetrics.getTotalResources());
+ // add CPU and Memory metrics
+ addHostCpuMetricsToResponse(metricsResponse, clusterId,
hostMetrics);
+ addHostMemoryMetricsToResponse(metricsResponse, clusterId,
hostMetrics);
+
+ metricsResponse.setHasAnnotation(clusterResponse.hasAnnotation());
+ metricsResponses.add(metricsResponse);
+ }
+ return metricsResponses;
+ }
+
+ private void addHostMemoryMetricsToResponse(ClusterMetricsResponse
metricsResponse, Long clusterId, HostMetrics hostMetrics) {
+ metricsResponse.setMemTotal(hostMetrics.getTotalMemory());
+ metricsResponse.setMemAllocated(hostMetrics.getMemoryAllocated(),
hostMetrics.getTotalMemory());
+ if (hostMetrics.getMemoryUsed() > 0L) {
+ metricsResponse.setMemUsed(hostMetrics.getMemoryUsed(),
hostMetrics.getTotalMemory());
+
metricsResponse.setMemMaxDeviation(hostMetrics.getMaximumMemoryUsage(),
hostMetrics.getMemoryUsed(), hostMetrics.getTotalHosts());
+ }
+ // Memory thresholds
+ final Double memoryThreshold =
AlertManager.MemoryCapacityThreshold.valueIn(clusterId);
+ final Float memoryDisableThreshold =
DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.valueIn(clusterId);
+ metricsResponse.setMemoryUsageThreshold(hostMetrics.getMemoryUsed(),
hostMetrics.getTotalMemory(), memoryThreshold);
+
metricsResponse.setMemoryUsageDisableThreshold(hostMetrics.getMemoryUsed(),
hostMetrics.getTotalMemory(), memoryDisableThreshold);
+
metricsResponse.setMemoryAllocatedThreshold(hostMetrics.getMemoryAllocated(),
hostMetrics.getTotalMemory(), memoryThreshold);
+
metricsResponse.setMemoryAllocatedDisableThreshold(hostMetrics.getMemoryAllocated(),
hostMetrics.getTotalMemory(), memoryDisableThreshold);
+ }
+
+ private void addHostCpuMetricsToResponse(ClusterMetricsResponse
metricsResponse, Long clusterId, HostMetrics hostMetrics) {
+ metricsResponse.setCpuTotal(hostMetrics.getTotalCpu());
+ metricsResponse.setCpuAllocated(hostMetrics.getCpuAllocated(),
hostMetrics.getTotalCpu());
+ if (hostMetrics.getCpuUsedPercentage() > 0L) {
+ metricsResponse.setCpuUsed(hostMetrics.getCpuUsedPercentage(),
hostMetrics.getTotalHosts());
+
metricsResponse.setCpuMaxDeviation(hostMetrics.getMaximumCpuUsage(),
hostMetrics.getCpuUsedPercentage(), hostMetrics.getTotalHosts());
+ }
+ // CPU thresholds
+ final Double cpuThreshold =
AlertManager.CPUCapacityThreshold.valueIn(clusterId);
+ final Float cpuDisableThreshold =
DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.valueIn(clusterId);
+
metricsResponse.setCpuUsageThreshold(hostMetrics.getCpuUsedPercentage(),
hostMetrics.getTotalHosts(), cpuThreshold);
+
metricsResponse.setCpuUsageDisableThreshold(hostMetrics.getCpuUsedPercentage(),
hostMetrics.getTotalHosts(), cpuDisableThreshold);
+
metricsResponse.setCpuAllocatedThreshold(hostMetrics.getCpuAllocated(),
hostMetrics.getTotalCpu(), cpuThreshold);
+
metricsResponse.setCpuAllocatedDisableThreshold(hostMetrics.getCpuAllocated(),
hostMetrics.getTotalCpu(), cpuDisableThreshold);
+ }
+
+
+ @Override
+ public List<ManagementServerMetricsResponse>
listManagementServerMetrics(List<ManagementServerResponse>
managementServerResponses) {
+ final List<ManagementServerMetricsResponse> metricsResponses = new
ArrayList<>();
+ if(LOGGER.isDebugEnabled()) {
+ LOGGER.debug(String.format("getting metrics for %d MS hosts",
managementServerResponses.size()));
+ }
+ for (final ManagementServerResponse managementServerResponse:
managementServerResponses) {
+ if(LOGGER.isDebugEnabled()) {
+ LOGGER.debug(String.format("processing metrics for MS hosts
%s", managementServerResponse.getId()));
}
- // 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());
+ ManagementServerMetricsResponse metricsResponse = new
ManagementServerMetricsResponse();
+
+ try {
+ BeanUtils.copyProperties(metricsResponse,
managementServerResponse);
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace(String.format("bean copy result %s", new
ReflectionToStringBuilder(metricsResponse,
ToStringStyle.SIMPLE_STYLE).toString()));
+ }
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to generate zone metrics response");
}
- // 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);
- metricsResponse.setHasAnnotation(clusterResponse.hasAnnotation());
+ updateManagementServerMetrics(metricsResponse,
managementServerResponse);
+
metricsResponses.add(metricsResponse);
}
return metricsResponses;
}
+ /**
+ * get the transient/in memory data
+ * @param metricsResponse
+ * @param managementServerResponse
Review comment:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]