Update license and poms
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / sync / TaskProcessingStats.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.sparky.sync;
22
23 import org.onap.aai.sparky.analytics.AbstractStatistics;
24 import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
25
26 /**
27  * The Class TaskProcessingStats.
28  */
29 public class TaskProcessingStats extends AbstractStatistics {
30
31   private static String TASK_AGE_STATS = "taskAgeStats";
32   private static String TASK_RESPONSE_STATS = "taskResponseStats";
33   private static String RESPONSE_SIZE_IN_BYTES = "taskResponseSizeInBytes";
34   // private static String QUEUE_ITEM_LENGTH = "queueItemLength";
35   private static String TPS = "transactionsPerSecond";
36
37   /**
38    * Instantiates a new task processing stats.
39    *
40    * @param config the config
41    */
42   public TaskProcessingStats(NetworkStatisticsConfig config) {
43
44     addHistogram(TASK_AGE_STATS, config.getTaskAgeHistogramLabel(),
45         config.getTaskAgeHistogramMaxYAxis(), config.getTaskAgeHistogramNumBins(),
46         config.getTaskAgeHistogramNumDecimalPoints());
47
48     addHistogram(TASK_RESPONSE_STATS, config.getResponseTimeHistogramLabel(),
49         config.getResponseTimeHistogramMaxYAxis(), config.getResponseTimeHistogramNumBins(),
50         config.getResponseTimeHistogramNumDecimalPoints());
51
52     addHistogram(RESPONSE_SIZE_IN_BYTES, config.getBytesHistogramLabel(),
53         config.getBytesHistogramMaxYAxis(), config.getBytesHistogramNumBins(),
54         config.getBytesHistogramNumDecimalPoints());
55
56     /*
57      * addHistogram(QUEUE_ITEM_LENGTH, config.getQueueLengthHistogramLabel(),
58      * config.getQueueLengthHistogramMaxYAxis(), config.getQueueLengthHistogramNumBins(),
59      * config.getQueueLengthHistogramNumDecimalPoints());
60      */
61
62     addHistogram(TPS, config.getTpsHistogramLabel(), config.getTpsHistogramMaxYAxis(),
63         config.getTpsHistogramNumBins(), config.getTpsHistogramNumDecimalPoints());
64
65   }
66
67   /*
68    * public void updateQueueItemLengthHistogram(long value) { updateHistogram(QUEUE_ITEM_LENGTH,
69    * value); }
70    */
71
72   /**
73    * Update task age stats histogram.
74    *
75    * @param value the value
76    */
77   public void updateTaskAgeStatsHistogram(long value) {
78     updateHistogram(TASK_AGE_STATS, value);
79   }
80
81   /**
82    * Update task response stats histogram.
83    *
84    * @param value the value
85    */
86   public void updateTaskResponseStatsHistogram(long value) {
87     updateHistogram(TASK_RESPONSE_STATS, value);
88   }
89
90   /**
91    * Update response size in bytes histogram.
92    *
93    * @param value the value
94    */
95   public void updateResponseSizeInBytesHistogram(long value) {
96     updateHistogram(RESPONSE_SIZE_IN_BYTES, value);
97   }
98
99   /**
100    * Update transactions per second histogram.
101    *
102    * @param value the value
103    */
104   public void updateTransactionsPerSecondHistogram(long value) {
105     updateHistogram(TPS, value);
106   }
107
108   /**
109    * Gets the statistics report.
110    *
111    * @param verboseEnabled the verbose enabled
112    * @param indentPadding the indent padding
113    * @return the statistics report
114    */
115   public String getStatisticsReport(boolean verboseEnabled, String indentPadding) {
116
117     StringBuilder sb = new StringBuilder();
118
119     sb.append("\n").append(getHistogramStats(TASK_AGE_STATS, verboseEnabled, indentPadding));
120     // sb.append("\n").append(getHistogramStats(QUEUE_ITEM_LENGTH, verboseEnabled, indentPadding));
121     sb.append("\n").append(getHistogramStats(TASK_RESPONSE_STATS, verboseEnabled, indentPadding));
122     sb.append("\n")
123         .append(getHistogramStats(RESPONSE_SIZE_IN_BYTES, verboseEnabled, indentPadding));
124     sb.append("\n").append(getHistogramStats(TPS, verboseEnabled, indentPadding));
125
126     return sb.toString();
127
128   }
129
130
131 }