Changing the license and trademark
[aai/sparky-be.git] / src / main / java / org / openecomp / sparky / synchronizer / TaskProcessingStats.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.openecomp.sparky.synchronizer;
24
25 import org.openecomp.sparky.analytics.AbstractStatistics;
26 import org.openecomp.sparky.synchronizer.config.TaskProcessorConfig;
27
28 /**
29  * The Class TaskProcessingStats.
30  */
31 public class TaskProcessingStats extends AbstractStatistics {
32
33   private static String TASK_AGE_STATS = "taskAgeStats";
34   private static String TASK_RESPONSE_STATS = "taskResponseStats";
35   private static String RESPONSE_SIZE_IN_BYTES = "taskResponseSizeInBytes";
36   // private static String QUEUE_ITEM_LENGTH = "queueItemLength";
37   private static String TPS = "transactionsPerSecond";
38
39   /**
40    * Instantiates a new task processing stats.
41    *
42    * @param config the config
43    */
44   public TaskProcessingStats(TaskProcessorConfig config) {
45
46     addHistogram(TASK_AGE_STATS, config.getTaskAgeHistogramLabel(),
47         config.getTaskAgeHistogramMaxYAxis(), config.getTaskAgeHistogramNumBins(),
48         config.getTaskAgeHistogramNumDecimalPoints());
49
50     addHistogram(TASK_RESPONSE_STATS, config.getResponseTimeHistogramLabel(),
51         config.getResponseTimeHistogramMaxYAxis(), config.getResponseTimeHistogramNumBins(),
52         config.getResponseTimeHistogramNumDecimalPoints());
53
54     addHistogram(RESPONSE_SIZE_IN_BYTES, config.getBytesHistogramLabel(),
55         config.getBytesHistogramMaxYAxis(), config.getBytesHistogramNumBins(),
56         config.getBytesHistogramNumDecimalPoints());
57
58     /*
59      * addHistogram(QUEUE_ITEM_LENGTH, config.getQueueLengthHistogramLabel(),
60      * config.getQueueLengthHistogramMaxYAxis(), config.getQueueLengthHistogramNumBins(),
61      * config.getQueueLengthHistogramNumDecimalPoints());
62      */
63
64     addHistogram(TPS, config.getTpsHistogramLabel(), config.getTpsHistogramMaxYAxis(),
65         config.getTpsHistogramNumBins(), config.getTpsHistogramNumDecimalPoints());
66
67   }
68
69   /*
70    * public void updateQueueItemLengthHistogram(long value) { updateHistogram(QUEUE_ITEM_LENGTH,
71    * value); }
72    */
73
74   /**
75    * Update task age stats histogram.
76    *
77    * @param value the value
78    */
79   public void updateTaskAgeStatsHistogram(long value) {
80     updateHistogram(TASK_AGE_STATS, value);
81   }
82
83   /**
84    * Update task response stats histogram.
85    *
86    * @param value the value
87    */
88   public void updateTaskResponseStatsHistogram(long value) {
89     updateHistogram(TASK_RESPONSE_STATS, value);
90   }
91
92   /**
93    * Update response size in bytes histogram.
94    *
95    * @param value the value
96    */
97   public void updateResponseSizeInBytesHistogram(long value) {
98     updateHistogram(RESPONSE_SIZE_IN_BYTES, value);
99   }
100
101   /**
102    * Update transactions per second histogram.
103    *
104    * @param value the value
105    */
106   public void updateTransactionsPerSecondHistogram(long value) {
107     updateHistogram(TPS, value);
108   }
109
110   /**
111    * Gets the statistics report.
112    *
113    * @param verboseEnabled the verbose enabled
114    * @param indentPadding the indent padding
115    * @return the statistics report
116    */
117   public String getStatisticsReport(boolean verboseEnabled, String indentPadding) {
118
119     StringBuilder sb = new StringBuilder();
120
121     sb.append("\n").append(getHistogramStats(TASK_AGE_STATS, verboseEnabled, indentPadding));
122     // sb.append("\n").append(getHistogramStats(QUEUE_ITEM_LENGTH, verboseEnabled, indentPadding));
123     sb.append("\n").append(getHistogramStats(TASK_RESPONSE_STATS, verboseEnabled, indentPadding));
124     sb.append("\n")
125         .append(getHistogramStats(RESPONSE_SIZE_IN_BYTES, verboseEnabled, indentPadding));
126     sb.append("\n").append(getHistogramStats(TPS, verboseEnabled, indentPadding));
127
128     return sb.toString();
129
130   }
131
132
133 }