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