mirror of https://github.com/apache/cloudstack.git
Merge 4aede97bd5 into b7d4df0a11
This commit is contained in:
commit
fe75949843
|
|
@ -59,7 +59,11 @@ import com.cloud.host.HostVO;
|
|||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.host.dao.HostTagsDao;
|
||||
import com.cloud.network.VirtualNetworkApplianceService;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.RouterHealthCheckResultDao;
|
||||
import com.cloud.network.dao.RouterHealthCheckResultVO;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.storage.ImageStore;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.Volume;
|
||||
|
|
@ -70,7 +74,9 @@ import com.cloud.user.dao.AccountDao;
|
|||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
|
|
@ -137,6 +143,10 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||
private HostTagsDao _hostTagsDao;
|
||||
@Inject
|
||||
private CAManager caManager;
|
||||
@Inject
|
||||
private DomainRouterDao domainRouterDao;
|
||||
@Inject
|
||||
private RouterHealthCheckResultDao routerHealthCheckResultDao;
|
||||
|
||||
public PrometheusExporterImpl() {
|
||||
super();
|
||||
|
|
@ -501,6 +511,35 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||
}
|
||||
}
|
||||
|
||||
private void addVirtualRouterHealthCheckMetrics(final List<Item> metricsList, final long dcId, final String zoneName, final String zoneUuid) {
|
||||
List<DomainRouterVO> routers = domainRouterDao.listByDataCenter(dcId);
|
||||
if (routers == null) {
|
||||
return;
|
||||
}
|
||||
for (DomainRouterVO router : routers) {
|
||||
if (router.getRole() != VirtualRouter.Role.VIRTUAL_ROUTER) {
|
||||
continue;
|
||||
}
|
||||
List<RouterHealthCheckResultVO> checks = routerHealthCheckResultDao.getHealthCheckResults(router.getId());
|
||||
if (checks == null || checks.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (RouterHealthCheckResultVO check : checks) {
|
||||
int resultValue = (check.getCheckResult() ==
|
||||
VirtualNetworkApplianceService.RouterHealthStatus.SUCCESS) ? 1 : 0;
|
||||
metricsList.add(new ItemVRHealthCheckResult(
|
||||
zoneName, router.getInstanceName(),
|
||||
check.getCheckName(), check.getCheckType(), resultValue));
|
||||
if (check.getLastUpdateTime() != null) {
|
||||
long epochSeconds = check.getLastUpdateTime().getTime() / 1000L;
|
||||
metricsList.add(new ItemVRHealthCheckLastCheck(
|
||||
zoneName, router.getInstanceName(),
|
||||
check.getCheckName(), check.getCheckType(), epochSeconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMetrics() {
|
||||
final List<Item> latestMetricsItems = new ArrayList<Item>();
|
||||
|
|
@ -518,6 +557,7 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||
addDomainMetrics(latestMetricsItems, zoneName, zoneUuid);
|
||||
addAccountMetrics(latestMetricsItems, dc.getId(), zoneName, zoneUuid);
|
||||
addVMsBySizeMetrics(latestMetricsItems, dc.getId(), zoneName, zoneUuid);
|
||||
addVirtualRouterHealthCheckMetrics(latestMetricsItems, dc.getId(), zoneName, zoneUuid);
|
||||
}
|
||||
addDomainLimits(latestMetricsItems);
|
||||
addDomainResourceCount(latestMetricsItems);
|
||||
|
|
@ -1180,4 +1220,56 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||
return String.format("%s{zone=\"%s\",hostname=\"%s\",ip=\"%s\"} %d", name, zoneName, hostName, hostIp, expiryTimestamp);
|
||||
}
|
||||
}
|
||||
|
||||
class ItemVRHealthCheckResult extends Item {
|
||||
String zoneName;
|
||||
String routerName;
|
||||
String checkName;
|
||||
String checkType;
|
||||
int result;
|
||||
|
||||
public ItemVRHealthCheckResult(String zn, String rn, String cn, String ct, int res) {
|
||||
super("cloudstack_virtualrouter_healthcheck_result",
|
||||
"Virtual Router Health Check result (1=success, 0=failure/unknown)",
|
||||
"gauge");
|
||||
zoneName = zn;
|
||||
routerName = rn;
|
||||
checkName = cn;
|
||||
checkType = ct;
|
||||
result = res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toMetricsString() {
|
||||
return String.format(
|
||||
"%s{checkname=\"%s\",checktype=\"%s\",zone=\"%s\",virtualrouter=\"%s\"} %d",
|
||||
name, checkName, checkType, zoneName, routerName, result);
|
||||
}
|
||||
}
|
||||
|
||||
class ItemVRHealthCheckLastCheck extends Item {
|
||||
String zoneName;
|
||||
String routerName;
|
||||
String checkName;
|
||||
String checkType;
|
||||
long lastCheckEpochSeconds;
|
||||
|
||||
public ItemVRHealthCheckLastCheck(String zn, String rn, String cn, String ct, long ts) {
|
||||
super("cloudstack_virtualrouter_healthcheck_lastcheck",
|
||||
"Virtual Router Health Check last check timestamp (Unix seconds)",
|
||||
"gauge");
|
||||
zoneName = zn;
|
||||
routerName = rn;
|
||||
checkName = cn;
|
||||
checkType = ct;
|
||||
lastCheckEpochSeconds = ts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toMetricsString() {
|
||||
return String.format(
|
||||
"%s{checkname=\"%s\",checktype=\"%s\",zone=\"%s\",virtualrouter=\"%s\"} %d",
|
||||
name, checkName, checkType, zoneName, routerName, lastCheckEpochSeconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue