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