plugins: Consider maintenance mode as offline for promethues stats (#4366)

If the resource state of hypervisor in "Maintenance" then it
should be considered as offline even though the agent state
is "Up". Since its in maintenance mode, it cant be used to
allocate VM's and hence can't be considered towards resource
allocation
This commit is contained in:
Rakesh 2020-10-14 12:12:02 +02:00 committed by GitHub
parent 191dbf7ea7
commit 2333d97098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -117,9 +117,10 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
continue;
}
total++;
if (host.getStatus() == Status.Up) {
if (host.getStatus() == Status.Up && !host.isInMaintenanceStates()) {
up++;
} else if (host.getStatus() == Status.Disconnected || host.getStatus() == Status.Down) {
} else if (host.getStatus() == Status.Disconnected || host.getStatus() == Status.Down ||
host.isInMaintenanceStates()) {
down++;
}

View File

@ -16,6 +16,7 @@
// under the License.
package com.cloud.api.query.vo;
import java.util.Arrays;
import java.util.Date;
import javax.persistence.Column;
@ -402,4 +403,10 @@ public class HostJoinVO extends BaseViewVO implements InternalIdentity, Identity
public boolean isAnnotated() {
return StringUtils.isNotBlank(annotation);
}
public boolean isInMaintenanceStates() {
return Arrays.asList(
ResourceState.Maintenance, ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance)
.contains(getResourceState());
}
}