5a6b76a842a04682c5742f506c9e6f7e7ba46f01
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distribution.reception.statistics;
23
24 import io.prometheus.client.Counter;
25
26 /**
27  * Class to hold statistical data for distribution component.
28  *
29  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
30  */
31 public class DistributionStatisticsManager {
32
33     private static final Counter TOTAL_DISTRIBUTION_RECEIVED_COUNT = Counter.build()
34                     .name("total_distribution_received_count")
35                     .help("Total number of distribution received.").register();
36     private static final Counter DISTRIBUTION_SUCCESS_COUNT = Counter.build()
37                     .name("distribution_success_count")
38                     .help("Total number of distribution successfully processed.").register();
39
40     private static final Counter DISTRIBUTION_FAILURE_COUNT = Counter.build()
41                     .name("distribution_failure_count")
42                     .help("Total number of distribution failures.").register();
43
44     private static final Counter TOTAL_DOWNLOAD_RECEIVED_COUNT = Counter.build()
45                     .name("total_download_received_count")
46                     .help("Total number of download received.").register();
47
48     private static final Counter DOWNLOAD_SUCCESS_COUNT = Counter.build()
49                     .name("download_success_count")
50                     .help("Total number of download successfully processed.").register();
51
52     private static final Counter DOWNLOAD_FAILURE_COUNT = Counter.build()
53                     .name("download_failure_count")
54                     .help("Total number of download failures.").register();
55
56     private DistributionStatisticsManager() {
57         throw new IllegalStateException("Instantiation of the class is not allowed");
58     }
59
60     /**
61      * Method to update the total distribution count.
62      *
63      */
64     public static void updateTotalDistributionCount() {
65         TOTAL_DISTRIBUTION_RECEIVED_COUNT.inc();
66     }
67
68     /**
69      * Method to update the distribution success count.
70      *
71      */
72     public static void updateDistributionSuccessCount() {
73         DISTRIBUTION_SUCCESS_COUNT.inc();
74     }
75
76     /**
77      * Method to update the distribution failure count.
78      *
79      */
80     public static void updateDistributionFailureCount() {
81         DISTRIBUTION_FAILURE_COUNT.inc();
82     }
83
84     /**
85      * Method to update the total download count.
86      *
87      */
88     public static void updateTotalDownloadCount() {
89         TOTAL_DOWNLOAD_RECEIVED_COUNT.inc();
90     }
91
92     /**
93      * Method to update the download success count.
94      *
95      */
96     public static void updateDownloadSuccessCount() {
97         DOWNLOAD_SUCCESS_COUNT.inc();
98     }
99
100     /**
101      * Method to update the download failure count.
102      *
103      */
104     public static void updateDownloadFailureCount() {
105         DOWNLOAD_FAILURE_COUNT.inc();
106     }
107
108     /**
109      * Returns the current value of totalDistributionCount.
110      *
111      * @return the totalDistributionCount
112      */
113     public static long getTotalDistributionCount() {
114         return (long) TOTAL_DISTRIBUTION_RECEIVED_COUNT.get();
115     }
116
117     /**
118      * Returns the current value of distributionSuccessCount.
119      *
120      * @return the distributionSuccessCount
121      */
122     public static long getDistributionSuccessCount() {
123         return (long) DISTRIBUTION_SUCCESS_COUNT.get();
124     }
125
126     /**
127      * Returns the current value of distributionFailureCount.
128      *
129      * @return the distributionFailureCount
130      */
131     public static long getDistributionFailureCount() {
132         return (long) DISTRIBUTION_FAILURE_COUNT.get();
133     }
134
135     /**
136      * Returns the current value of totalDownloadCount.
137      *
138      * @return the totalDownloadCount
139      */
140     public static long getTotalDownloadCount() {
141         return (long) TOTAL_DOWNLOAD_RECEIVED_COUNT.get();
142     }
143
144     /**
145      * Returns the current value of downloadSuccessCount.
146      *
147      * @return the downloadSuccessCount
148      */
149     public static long getDownloadSuccessCount() {
150         return (long) DOWNLOAD_SUCCESS_COUNT.get();
151     }
152
153     /**
154      * Returns the current value of downloadFailureCount.
155      *
156      * @return the downloadFailureCount
157      */
158     public static long getDownloadFailureCount() {
159         return (long) DOWNLOAD_FAILURE_COUNT.get();
160     }
161
162     /**
163      * Reset all the statistics counts to 0.
164      */
165     public static void resetAllStatistics() {
166         TOTAL_DISTRIBUTION_RECEIVED_COUNT.clear();
167         DISTRIBUTION_SUCCESS_COUNT.clear();
168         DISTRIBUTION_FAILURE_COUNT.clear();
169         TOTAL_DOWNLOAD_RECEIVED_COUNT.clear();
170         DOWNLOAD_SUCCESS_COUNT.clear();
171         DOWNLOAD_FAILURE_COUNT.clear();
172     }
173 }