mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Prometheus exporter fix cpu/memory usage labels (#7629)
This commit is contained in:
parent
dea1373480
commit
9df23f951b
@ -28,6 +28,7 @@ import javax.inject.Inject;
|
|||||||
import com.cloud.configuration.dao.ResourceCountDao;
|
import com.cloud.configuration.dao.ResourceCountDao;
|
||||||
import com.cloud.dc.DedicatedResourceVO;
|
import com.cloud.dc.DedicatedResourceVO;
|
||||||
import com.cloud.dc.dao.DedicatedResourceDao;
|
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||||
|
import com.cloud.host.HostStats;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.dao.AccountDao;
|
import com.cloud.user.dao.AccountDao;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||||
@ -127,6 +128,8 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||||||
Map<String, Integer> upHosts = new HashMap<>();
|
Map<String, Integer> upHosts = new HashMap<>();
|
||||||
Map<String, Integer> downHosts = new HashMap<>();
|
Map<String, Integer> downHosts = new HashMap<>();
|
||||||
|
|
||||||
|
HostStats hostStats;
|
||||||
|
|
||||||
for (final HostVO host : hostDao.listAll()) {
|
for (final HostVO host : hostDao.listAll()) {
|
||||||
if (host == null || host.getType() != Host.Type.Routing || host.getDataCenterId() != dcId) {
|
if (host == null || host.getType() != Host.Type.Routing || host.getDataCenterId() != dcId) {
|
||||||
continue;
|
continue;
|
||||||
@ -144,6 +147,7 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||||||
metricsList.add(new ItemHostIsDedicated(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), isDedicated));
|
metricsList.add(new ItemHostIsDedicated(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), isDedicated));
|
||||||
|
|
||||||
String hostTags = markTagMaps(host, totalHosts, upHosts, downHosts);
|
String hostTags = markTagMaps(host, totalHosts, upHosts, downHosts);
|
||||||
|
hostStats = ApiDBUtils.getHostStatistics(host.getId());
|
||||||
|
|
||||||
// Get account, domain details for dedicated hosts
|
// Get account, domain details for dedicated hosts
|
||||||
if (isDedicated == 1) {
|
if (isDedicated == 1) {
|
||||||
@ -157,10 +161,14 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||||||
|
|
||||||
final String cpuFactor = String.valueOf(CapacityManager.CpuOverprovisioningFactor.valueIn(host.getClusterId()));
|
final String cpuFactor = String.valueOf(CapacityManager.CpuOverprovisioningFactor.valueIn(host.getClusterId()));
|
||||||
final CapacityVO cpuCapacity = capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU);
|
final CapacityVO cpuCapacity = capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU);
|
||||||
|
final double cpuUsedMhz = hostStats.getCpuUtilization() * host.getCpus() * host.getSpeed() / 100.0 ;
|
||||||
|
|
||||||
if (cpuCapacity != null && cpuCapacity.getCapacityState() == CapacityState.Enabled) {
|
if (cpuCapacity != null && cpuCapacity.getCapacityState() == CapacityState.Enabled) {
|
||||||
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, cpuCapacity.getUsedCapacity(), isDedicated, hostTags));
|
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, ALLOCATED, cpuCapacity.getUsedCapacity(), isDedicated, hostTags));
|
||||||
|
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, cpuUsedMhz, isDedicated, hostTags));
|
||||||
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, cpuCapacity.getTotalCapacity(), isDedicated, hostTags));
|
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, cpuCapacity.getTotalCapacity(), isDedicated, hostTags));
|
||||||
} else {
|
} else {
|
||||||
|
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, ALLOCATED, 0L, isDedicated, hostTags));
|
||||||
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, 0L, isDedicated, hostTags));
|
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, 0L, isDedicated, hostTags));
|
||||||
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, 0L, isDedicated, hostTags));
|
metricsList.add(new ItemHostCpu(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, 0L, isDedicated, hostTags));
|
||||||
}
|
}
|
||||||
@ -168,10 +176,12 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||||||
final String memoryFactor = String.valueOf(CapacityManager.MemOverprovisioningFactor.valueIn(host.getClusterId()));
|
final String memoryFactor = String.valueOf(CapacityManager.MemOverprovisioningFactor.valueIn(host.getClusterId()));
|
||||||
final CapacityVO memCapacity = capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
|
final CapacityVO memCapacity = capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
|
||||||
if (memCapacity != null && memCapacity.getCapacityState() == CapacityState.Enabled) {
|
if (memCapacity != null && memCapacity.getCapacityState() == CapacityState.Enabled) {
|
||||||
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, memCapacity.getUsedCapacity(), isDedicated, hostTags));
|
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, ALLOCATED, memCapacity.getUsedCapacity(), isDedicated, hostTags));
|
||||||
|
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, hostStats.getUsedMemory(), isDedicated, hostTags));
|
||||||
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, TOTAL, memCapacity.getTotalCapacity(), isDedicated, hostTags));
|
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, TOTAL, memCapacity.getTotalCapacity(), isDedicated, hostTags));
|
||||||
} else {
|
} else {
|
||||||
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, 0L, isDedicated, hostTags));
|
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, ALLOCATED, 0L, isDedicated, hostTags));
|
||||||
|
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, 0, isDedicated, hostTags));
|
||||||
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, TOTAL, 0L, isDedicated, hostTags));
|
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, TOTAL, 0L, isDedicated, hostTags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user