1
22
23 package com.liferay.portal.monitoring.statistics.portal;
24
25 import com.liferay.portal.monitoring.MonitoringException;
26 import com.liferay.portal.monitoring.statistics.RequestStatistics;
27 import com.liferay.portal.monitoring.statistics.SummaryStatistics;
28
29 import java.util.Set;
30
31
37 public class ServerSummaryStatistics implements SummaryStatistics {
38
39 public ServerSummaryStatistics(ServerStatistics serverStatistics) {
40 _serverStatistics = serverStatistics;
41 }
42
43 public long getAverageTime() {
44 long averageTime = 0;
45
46 Set<CompanyStatistics> companyStatisticsSet =
47 _serverStatistics.getCompanyStatisticsSet();
48
49 for (CompanyStatistics companyStatistics : companyStatisticsSet) {
50 RequestStatistics requestStatistics =
51 companyStatistics.getRequestStatistics();
52
53 averageTime += requestStatistics.getAverageTime();
54 }
55
56 return averageTime / companyStatisticsSet.size();
57 }
58
59 public long getAverageTimeByCompany(long companyId)
60 throws MonitoringException {
61
62 return getRequestStatistics(companyId).getAverageTime();
63 }
64
65 public long getAverageTimeByCompany(String webId)
66 throws MonitoringException {
67
68 return getRequestStatistics(webId).getAverageTime();
69 }
70
71 public long getErrorCount() {
72 int errorCount = 0;
73
74 for (CompanyStatistics companyStatistics :
75 _serverStatistics.getCompanyStatisticsSet()) {
76
77 errorCount +=
78 companyStatistics.getRequestStatistics().getErrorCount();
79 }
80
81 return errorCount;
82 }
83
84 public long getErrorCountByCompany(long companyId)
85 throws MonitoringException {
86
87 return getRequestStatistics(companyId).getErrorCount();
88 }
89
90 public long getErrorCountByCompany(String webId)
91 throws MonitoringException {
92
93 return getRequestStatistics(webId).getErrorCount();
94 }
95
96 public long getMaxTime() {
97 long maxTime = 0;
98
99 for (CompanyStatistics companyStatistics :
100 _serverStatistics.getCompanyStatisticsSet()) {
101
102 if (companyStatistics.getMaxTime() > maxTime) {
103 maxTime = companyStatistics.getMaxTime();
104 }
105 }
106
107 return maxTime;
108 }
109
110 public long getMaxTimeByCompany(long companyId) throws MonitoringException {
111 return getRequestStatistics(companyId).getMaxTime();
112 }
113
114 public long getMaxTimeByCompany(String webId) throws MonitoringException {
115 return getRequestStatistics(webId).getMaxTime();
116 }
117
118 public long getMinTime() {
119 long minTime = 0;
120
121 for (CompanyStatistics companyStatistics :
122 _serverStatistics.getCompanyStatisticsSet()) {
123
124 if (companyStatistics.getMinTime() < minTime) {
125 minTime = companyStatistics.getMinTime();
126 }
127 }
128
129 return minTime;
130 }
131
132 public long getMinTimeByCompany(long companyId)
133 throws MonitoringException {
134
135 return getRequestStatistics(companyId).getMinTime();
136 }
137
138 public long getMinTimeByCompany(String webId)
139 throws MonitoringException {
140
141 return getRequestStatistics(webId).getMinTime();
142 }
143
144 public long getRequestCount() {
145 int requestCount = 0;
146
147 for (CompanyStatistics companyStatistics :
148 _serverStatistics.getCompanyStatisticsSet()) {
149
150 requestCount +=
151 companyStatistics.getRequestStatistics().getRequestCount();
152 }
153
154 return requestCount;
155 }
156
157 public long getRequestCountByCompany(long companyId)
158 throws MonitoringException {
159
160 return getRequestStatistics(companyId).getRequestCount();
161 }
162
163 public long getRequestCountByCompany(String webId)
164 throws MonitoringException {
165
166 return getRequestStatistics(webId).getRequestCount();
167 }
168
169 public long getSuccessCount() {
170 int successCount = 0;
171
172 for (CompanyStatistics companyStatistics :
173 _serverStatistics.getCompanyStatisticsSet()) {
174
175 successCount +=
176 companyStatistics.getRequestStatistics().getSuccessCount();
177 }
178
179 return successCount;
180 }
181
182 public long getSuccessCountByCompany(long companyId)
183 throws MonitoringException {
184
185 return getRequestStatistics(companyId).getSuccessCount();
186 }
187
188 public long getSuccessCountByCompany(String webId)
189 throws MonitoringException {
190
191 return getRequestStatistics(webId).getSuccessCount();
192 }
193
194 public long getTimeoutCount() {
195 int timeoutCount = 0;
196
197 for (CompanyStatistics companyStatistics :
198 _serverStatistics.getCompanyStatisticsSet()) {
199
200 timeoutCount +=
201 companyStatistics.getRequestStatistics().getTimeoutCount();
202 }
203
204 return timeoutCount;
205 }
206
207 public long getTimeoutCountByCompany(long companyId)
208 throws MonitoringException {
209
210 return getRequestStatistics(companyId).getTimeoutCount();
211 }
212
213 public long getTimeoutCountByCompany(String webId)
214 throws MonitoringException {
215
216 return getRequestStatistics(webId).getTimeoutCount();
217 }
218
219 protected RequestStatistics getRequestStatistics(long companyId)
220 throws MonitoringException {
221
222 try {
223 CompanyStatistics companyStatistics =
224 _serverStatistics.getCompanyStatistics(companyId);
225
226 return companyStatistics.getRequestStatistics();
227 }
228 catch (Exception e) {
229 throw new MonitoringException(
230 "Unable to get company with company id " + companyId, e);
231 }
232 }
233
234 protected RequestStatistics getRequestStatistics(String webId)
235 throws MonitoringException {
236
237 try {
238 CompanyStatistics companyStatistics =
239 _serverStatistics.getCompanyStatistics(webId);
240
241 return companyStatistics.getRequestStatistics();
242 }
243 catch (Exception e) {
244 throw new MonitoringException(
245 "Unable to get company with web id " + webId, e);
246 }
247 }
248
249 private ServerStatistics _serverStatistics;
250
251 }