From 3e8c0684ed53c5cff704eac7321b08f31cdddc75 Mon Sep 17 00:00:00 2001 From: Ben <5091256+benj-n@users.noreply.github.com> Date: Tue, 23 May 2023 01:44:43 -0400 Subject: [PATCH] Prometheus: Ensure tagged hosts maintenance status is reported consistently (#7471) When a host is not tagged, its maintenance status is reported in the cloudstack_hosts_total metric: maintenance_enabled is OFFLINE, maintenance_disabled is ONLINE. When a host is tagged, its maintenance status is now also verified to ensure consistent behaviour. In prometheus exporter, maintenance status for cloudstack_hosts_total_by_tag is not checked. While it is checked for cloudstack_hosts_total metric. Classified by_tag or not, metrics should be the same. Fixes: #7470 --- .../org/apache/cloudstack/metrics/PrometheusExporterImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java index 7d6ed876323..3f69ccdb3c1 100644 --- a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java +++ b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java @@ -212,9 +212,9 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp private String markTagMaps(HostVO host, Map totalHosts, Map upHosts, Map downHosts) { List hostTags = _hostTagsDao.getHostTags(host.getId()); markTags(hostTags,totalHosts); - if (host.getStatus() == Status.Up) { + if (host.getStatus() == Status.Up && !host.isInMaintenanceStates()) { markTags(hostTags, upHosts); - } else if (host.getStatus() == Status.Disconnected || host.getStatus() == Status.Down) { + } else if (host.getStatus() == Status.Disconnected || host.getStatus() == Status.Down || host.isInMaintenanceStates()) { markTags(hostTags, downHosts); } return StringUtils.join(hostTags, ",");