diff options
author | 2022-01-07 01:38:40 -0500 | |
---|---|---|
committer | 2022-01-10 16:08:30 -0500 | |
commit | 58eae5d260f4e41ae439b733404fd1bc7dca453b (patch) | |
tree | e48dd9fc1a81191cf61184e2e43b7ef2e55bb671 /model/engine-model/src/main | |
parent | 63cd91c92e53349283ef920bb1dfd9efa1ca3a48 (diff) |
Prometheues metrics for APEX engine stats
Issue-ID: POLICY-3846
Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca>
Change-Id: I385446683372548f3fed6d609a9e85633ec2916d
Diffstat (limited to 'model/engine-model/src/main')
2 files changed, 74 insertions, 11 deletions
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java index f77fe1910..63c8706d2 100644 --- a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java +++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -34,13 +35,23 @@ import javax.xml.bind.annotation.XmlType; @XmlType(name = "AxEngineState", namespace = "http://www.onap.org/policy/apex-pdp") public enum AxEngineState { /** The state of the engine is not known. */ - UNDEFINED, + UNDEFINED(0), /** The engine is stopped. */ - STOPPED, + STOPPED(1), /** The engine is running and is waiting to execute a policy. */ - READY, + READY(2), /** The engine is running and is executing a policy. */ - EXECUTING, - /** The engine has been ordered to stop and is stoping. */ - STOPPING; -} + EXECUTING(3), + /** The engine has been ordered to stop and is stopping. */ + STOPPING(4); + + private final int stateIdentifier; + + AxEngineState(int stateIdentifier) { + this.stateIdentifier = stateIdentifier; + } + + public int getStateIdentifier() { + return stateIdentifier; + } +}
\ No newline at end of file diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java index 916525900..39a90800d 100644 --- a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java +++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,8 @@ package org.onap.policy.apex.model.enginemodel.concepts; +import io.prometheus.client.Gauge; +import io.prometheus.client.Histogram; import java.text.SimpleDateFormat; import java.util.List; import javax.persistence.Column; @@ -59,6 +62,22 @@ import org.onap.policy.common.utils.validation.Assertions; public class AxEngineStats extends AxConcept { private static final long serialVersionUID = -6981129081962785368L; private static final int HASH_CODE_PRIME = 32; + static final String ENGINE_INSTANCE_ID = "engine_instance_id"; + static final Gauge ENGINE_EVENTS_EXECUTED_COUNT = Gauge.build().name("apex_engine_events_executed_count") + .labelNames(ENGINE_INSTANCE_ID) + .help("Total number of APEX events processed by the engine.").register(); + static final Gauge ENGINE_UPTIME = Gauge.build().name("apex_engine_uptime") + .labelNames(ENGINE_INSTANCE_ID) + .help("Time elapsed since the engine was started.").register(); + static final Gauge ENGINE_START_TIMESTAMP = Gauge.build().name("apex_engine_last_start_timestamp_epoch") + .labelNames(ENGINE_INSTANCE_ID) + .help("Epoch timestamp of the instance when engine was last started.").register(); + static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.build().name("apex_engine_average_execution_time_seconds") + .labelNames(ENGINE_INSTANCE_ID) + .help("Average time taken to execute an APEX policy in seconds.").register(); + static final Histogram ENGINE_LAST_EXECUTION_TIME = Histogram.build() + .name("apex_engine_last_execution_time").labelNames(ENGINE_INSTANCE_ID) + .help("Time taken to execute the last APEX policy in seconds.").register(); @EmbeddedId @XmlElement(name = "key", required = true) @@ -104,6 +123,22 @@ public class AxEngineStats extends AxConcept { upTime = 0; lastEnterTime = 0; lastStart = 0; + initEngineMetricsWithPrometheus(); + } + + /** + * Register the APEX engine metrics with Prometheus. + */ + private void initEngineMetricsWithPrometheus() { + var engineId = getKey().getParentArtifactKey().getId(); + if (engineId.startsWith(AxKey.NULL_KEY_NAME)) { + return; + } + ENGINE_UPTIME.labels(engineId).set(upTime / 1000d); + ENGINE_EVENTS_EXECUTED_COUNT.labels(engineId).set(this.eventCount); + ENGINE_START_TIMESTAMP.labels(engineId).set(this.lastStart); + ENGINE_AVG_EXECUTION_TIME.labels(engineId).set(this.averageExecutionTime / 1000d); + ENGINE_LAST_EXECUTION_TIME.labels(engineId).observe(this.lastExecutionTime / 1000d); } /** @@ -147,6 +182,7 @@ public class AxEngineStats extends AxConcept { this.averageExecutionTime = averageExecutionTime; this.upTime = upTime; this.lastStart = lastStart; + initEngineMetricsWithPrometheus(); } /** @@ -218,6 +254,8 @@ public class AxEngineStats extends AxConcept { */ public void setEventCount(final long eventCount) { this.eventCount = eventCount; + ENGINE_EVENTS_EXECUTED_COUNT.labels(getKey().getParentArtifactKey().getId()) + .set(this.eventCount); } /** @@ -236,6 +274,8 @@ public class AxEngineStats extends AxConcept { */ public void setLastExecutionTime(final long lastExecutionTime) { this.lastExecutionTime = lastExecutionTime; + ENGINE_LAST_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId()) + .observe(this.lastExecutionTime / 1000d); } /** @@ -254,6 +294,8 @@ public class AxEngineStats extends AxConcept { */ public void setAverageExecutionTime(final double averageExecutionTime) { this.averageExecutionTime = averageExecutionTime; + ENGINE_AVG_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId()) + .set(this.averageExecutionTime / 1000d); } /** @@ -275,6 +317,7 @@ public class AxEngineStats extends AxConcept { */ public void setUpTime(final long upTime) { this.upTime = upTime; + ENGINE_UPTIME.labels(getKey().getParentArtifactKey().getId()).set(this.upTime / 1000d); } /** @@ -284,6 +327,7 @@ public class AxEngineStats extends AxConcept { */ private void setLastStart(final long lastStart) { this.lastStart = lastStart; + ENGINE_START_TIMESTAMP.labels(getKey().getParentArtifactKey().getId()).set(this.lastStart); } /** @@ -306,6 +350,7 @@ public class AxEngineStats extends AxConcept { upTime = 0; lastEnterTime = 0; lastStart = 0; + initEngineMetricsWithPrometheus(); } /** @@ -321,6 +366,7 @@ public class AxEngineStats extends AxConcept { } lastEnterTime = now; timeStamp = now; + ENGINE_EVENTS_EXECUTED_COUNT.labels(getKey().getParentArtifactKey().getId()).set(this.eventCount); } /** @@ -329,10 +375,14 @@ public class AxEngineStats extends AxConcept { public synchronized void executionExit() { final long now = System.currentTimeMillis(); lastExecutionTime = now - lastEnterTime; + ENGINE_LAST_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId()) + .observe(this.lastExecutionTime / 1000d); averageExecutionTime = ((averageExecutionTime * (eventCount - 1.0)) + lastExecutionTime) / eventCount; lastEnterTime = 0; timeStamp = System.currentTimeMillis(); + ENGINE_AVG_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId()) + .set(this.averageExecutionTime / 1000d); } /** @@ -352,6 +402,7 @@ public class AxEngineStats extends AxConcept { timeStamp = now; upTime += (timeStamp - this.getLastStart()); this.setLastStart(0); + ENGINE_UPTIME.labels(getKey().getParentArtifactKey().getId()).set(this.upTime / 1000d); } /** @@ -417,6 +468,7 @@ public class AxEngineStats extends AxConcept { copy.setAverageExecutionTime(averageExecutionTime); copy.setUpTime(upTime); copy.setLastStart(lastStart); + initEngineMetricsWithPrometheus(); return copy; } @@ -514,4 +566,4 @@ public class AxEngineStats extends AxConcept { return Long.compare(lastStart, other.lastStart); } -} +}
\ No newline at end of file |