2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.service.engine.main;
25 import io.prometheus.client.Counter;
26 import java.util.concurrent.atomic.AtomicLong;
27 import lombok.NoArgsConstructor;
28 import org.onap.policy.common.utils.services.Registry;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 public class ApexPolicyStatisticsManager {
34 private static final Logger LOGGER = LoggerFactory.getLogger(ApexPolicyStatisticsManager.class);
36 static final Counter POLICY_DEPLOY_REQUESTS_COUNTER = Counter.build()
37 .name("policies_deploy_requests_total")
38 .help("Total number of TOSCA policies deploy requests.").register();
39 static final Counter POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER = Counter.build()
40 .name("policies_deploy_requests_success")
41 .help("Total number of TOSCA policies deploy requests that succeeded.").register();
42 static final Counter POLICY_DEPLOY_REQUESTS_FAILED_COUNTER = Counter.build()
43 .name("policies_deploy_requests_failed")
44 .help("Total number of TOSCA policies deploy requests that failed.").register();
45 static final Counter POLICY_UNDEPLOY_REQUESTS_COUNTER = Counter.build()
46 .name("policies_undeploy_requests_total").help("Total number of TOSCA policies undeploy requests.")
48 static final Counter POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER = Counter.build()
49 .name("policies_undeploy_requests_success")
50 .help("Total number of TOSCA policies undeploy requests that succeeded.").register();
51 static final Counter POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER = Counter.build()
52 .name("policies_undeploy_requests_failed")
53 .help("Total number of TOSCA policies undeploy requests that failed.").register();
55 public static final String REG_APEX_PDP_POLICY_COUNTER = "object:pdp/statistics/policy/counter";
57 private final AtomicLong policyDeployCount = new AtomicLong(0);
58 private final AtomicLong policyDeploySuccessCount = new AtomicLong(0);
59 private final AtomicLong policyDeployFailCount = new AtomicLong(0);
60 private final AtomicLong policyUndeployCount = new AtomicLong(0);
61 private final AtomicLong policyUndeploySuccessCount = new AtomicLong(0);
62 private final AtomicLong policyUndeployFailCount = new AtomicLong(0);
63 private final AtomicLong policyExecutedCount = new AtomicLong(0);
64 private final AtomicLong policyExecutedSuccessCount = new AtomicLong(0);
65 private final AtomicLong policyExecutedFailCount = new AtomicLong(0);
68 * To get the ApexPolicyStatisticsManager in Registry.
70 * @return ApexPolicyStatisticsManager The obj in Registry.
72 public static ApexPolicyStatisticsManager getInstanceFromRegistry() {
73 ApexPolicyStatisticsManager instance = null;
75 instance = Registry.get(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER);
76 } catch (IllegalArgumentException e) {
77 LOGGER.debug("ApexPolicyStatisticsManager is not registered yet");
84 * Update the policy deploy count.
86 public void updatePolicyDeployCounter(final boolean isSuccessful) {
87 this.policyDeployCount.incrementAndGet();
88 POLICY_DEPLOY_REQUESTS_COUNTER.inc();
90 this.policyDeployFailCount.incrementAndGet();
91 POLICY_DEPLOY_REQUESTS_FAILED_COUNTER.inc();
93 this.policyDeploySuccessCount.incrementAndGet();
94 POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER.inc();
99 * Update the policy executed count.
101 public void updatePolicyExecutedCounter(final boolean isSuccessful) {
102 this.policyExecutedCount.incrementAndGet();
104 this.policyExecutedSuccessCount.incrementAndGet();
106 this.policyExecutedFailCount.incrementAndGet();
112 * Update the policy undeploy count.
114 public void updatePolicyUndeployCounter(final boolean isSuccessful) {
115 this.policyUndeployCount.incrementAndGet();
116 POLICY_UNDEPLOY_REQUESTS_COUNTER.inc();
118 this.policyUndeploySuccessCount.incrementAndGet();
119 POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER.inc();
121 this.policyUndeployFailCount.incrementAndGet();
122 POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER.inc();
126 public long getPolicyDeployCount() {
127 return Double.valueOf(POLICY_DEPLOY_REQUESTS_COUNTER.get()).longValue();
130 public long getPolicyDeployFailCount() {
131 return Double.valueOf(POLICY_DEPLOY_REQUESTS_FAILED_COUNTER.get()).longValue();
134 public long getPolicyDeploySuccessCount() {
135 return Double.valueOf(POLICY_DEPLOY_REQUESTS_SUCCESS_COUNTER.get()).longValue();
138 public long getPolicyExecutedCount() {
139 return policyExecutedCount.get();
142 public long getPolicyExecutedSuccessCount() {
143 return policyExecutedSuccessCount.get();
146 public long getPolicyExecutedFailCount() {
147 return policyExecutedFailCount.get();
150 public long getPolicyUndeployCount() {
151 return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_COUNTER.get()).longValue();
154 public long getPolicyUndeploySuccessCount() {
155 return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_SUCCESS_COUNTER.get()).longValue();
158 public long getPolicyUndeployFailCount() {
159 return Double.valueOf(POLICY_UNDEPLOY_REQUESTS_FAILED_COUNTER.get()).longValue();