Skip to content

Commit cf47f62

Browse files
committed
Merge pull request #346 from smithkm/location-stats-17
#343/#344 Updated stats on home page, 1.7.x
2 parents f5c5b2d + 216e38c commit cf47f62

File tree

4 files changed

+87
-22
lines changed

4 files changed

+87
-22
lines changed

geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.apache.commons.logging.Log;
4141
import org.apache.commons.logging.LogFactory;
4242
import org.geowebcache.config.Configuration;
43+
import org.geowebcache.config.ConfigurationException;
44+
import org.geowebcache.config.XMLConfiguration;
4345
import org.geowebcache.conveyor.Conveyor;
4446
import org.geowebcache.conveyor.Conveyor.CacheResult;
4547
import org.geowebcache.conveyor.ConveyorTile;
@@ -97,6 +99,8 @@ public class GeoWebCacheDispatcher extends AbstractController {
9799

98100
private String servletPrefix = null;
99101

102+
private Configuration mainConfiguration;
103+
100104
/**
101105
* Should be invoked through Spring
102106
*
@@ -111,7 +115,8 @@ public GeoWebCacheDispatcher(TileLayerDispatcher tileLayerDispatcher,
111115
this.gridSetBroker = gridSetBroker;
112116
this.runtimeStats = runtimeStats;
113117
this.storageBroker = storageBroker;
114-
118+
this.mainConfiguration = mainConfiguration;
119+
115120
if (mainConfiguration.isRuntimeStatsEnabled()) {
116121
this.runtimeStats.start();
117122
} else {
@@ -460,6 +465,11 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
460465
str.append(runtimeStats.getHTMLStats());
461466
str.append("</table>\n");
462467
}
468+
if(!Boolean.parseBoolean(GeoWebCacheExtensions.getProperty("GEOWEBCACHE_HIDE_STORAGE_LOCATIONS")))
469+
{
470+
appendStorageLocations(str);
471+
}
472+
463473
if(storageBroker != null){
464474
appendInternalCacheStats(str);
465475
}
@@ -468,6 +478,39 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
468478
writePage(response, 200, str.toString());
469479
}
470480

481+
private void appendStorageLocations(StringBuilder str) {
482+
str.append("<h3>Storage Locations</h3>\n");
483+
str.append("<table class=\"stats\">\n");
484+
str.append("<tbody>");
485+
XMLConfiguration config;
486+
if(mainConfiguration instanceof XMLConfiguration) {
487+
config = (XMLConfiguration) mainConfiguration;
488+
} else {
489+
config = GeoWebCacheExtensions.bean(XMLConfiguration.class);
490+
}
491+
String configLoc;
492+
String localStorageLoc;
493+
// TODO: Disk Quota location
494+
try {
495+
configLoc = config.getConfigLocation();
496+
} catch (ConfigurationException ex) {
497+
configLoc = "Error";
498+
log.error("Could not find config location", ex);
499+
}
500+
try {
501+
localStorageLoc = defaultStorageFinder.getDefaultPath();
502+
} catch (ConfigurationException ex) {
503+
localStorageLoc = "Error";
504+
log.error("Could not find local cache location", ex);
505+
}
506+
str.append("<tr><th scope=\"row\">Config file:</th><td><tt>").append(configLoc).append("</tt></td></tr>");
507+
str.append("<tr><th scope=\"row\">Local Storage:</th><td><tt>").append(localStorageLoc).append("</tt></td></tr>");
508+
str.append("</tbody>");
509+
510+
str.append("</tbody>");
511+
str.append("</table>\n");
512+
}
513+
471514
/**
472515
* Wrapper method for writing an error back to the client, and logging it at the same time.
473516
*

geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ private File findConfigFile() throws ConfigurationException {
270270
File xmlFile = new File(configDirectory, configFileName);
271271
return xmlFile;
272272
}
273+
274+
public String getConfigLocation() throws ConfigurationException {
275+
File f = findConfigFile();
276+
try {
277+
return f.getCanonicalPath();
278+
} catch (IOException ex) {
279+
log.error("Could not canonize config path", ex);
280+
return f.getPath();
281+
}
282+
}
273283

274284
private File findOrCreateConfFile() throws ConfigurationException {
275285
File xmlFile = findConfigFile();

geowebcache/core/src/main/java/org/geowebcache/stats/RuntimeStats.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,31 @@ public String getHTMLStats() {
151151

152152
StringBuilder str = new StringBuilder();
153153

154-
str.append("<table border=\"0\" cellspacing=\"5\">");
155-
154+
str.append("<table border=\"0\" cellspacing=\"5\" class=\"stats\">");
156155

157156
synchronized(bytes) {
158157
// Starting time
159-
str.append("<tr><td colspan=\"2\">Started:</td><td colspan=\"3\">");
158+
str.append("<tbody>");
159+
str.append("<tr><th colspan=\"2\" scope=\"row\">Started:</th><td colspan=\"3\">");
160160
str.append(ServletUtils.formatTimestamp(this.startTime)+ " (" + formatTimeDiff(runningTime) + ") ");
161161
str.append("</td></tr>\n");
162162

163-
str.append("<tr><td colspan=\"2\">Total number of requests:</td><td colspan=\"3\">"+totalRequests);
163+
str.append("<tr><th colspan=\"2\" scope=\"row\">Total number of requests:</th><td colspan=\"3\">"+totalRequests);
164164
str.append(" (" + totalRequests / (runningTime) +"/s ) ");
165165
str.append("</td></tr>\n");
166166

167-
str.append("<tr><td colspan=\"2\">Total number of untiled WMS requests:</td><td colspan=\"3\">"+totalWMS);
167+
str.append("<tr><th colspan=\"2\" scope=\"row\">Total number of untiled WMS requests:</th><td colspan=\"3\">"+totalWMS);
168168
str.append(" (" + totalWMS / (runningTime) +"/s ) ");
169169
str.append("</td></tr>\n");
170170

171-
str.append("<tr><td colspan=\"2\">Total number of bytes:</td><td colspan=\"3\">"+totalBytes);
171+
str.append("<tr><th colspan=\"2\" scope=\"row\">Total number of bytes:</th><td colspan=\"3\">"+totalBytes);
172172
str.append(" ("+formatBits((totalBytes*8.0)/(runningTime))+") ");
173173
str.append("</td></tr>\n");
174174

175-
str.append("<tr><td colspan=\"5\"> </td></tr>");
175+
str.append("</tbody>");
176+
str.append("<tbody>");
176177

177-
str.append("<tr><td colspan=\"2\">Cache hit ratio:</td><td colspan=\"3\">");
178+
str.append("<tr><th colspan=\"2\" scope=\"row\">Cache hit ratio:</th><td colspan=\"3\">");
178179
if(totalHits + totalMisses > 0) {
179180
double hitPercentage = (totalHits * 100.0) / (totalHits + totalMisses);
180181
int rounded = (int) Math.round(hitPercentage * 100.0);
@@ -187,7 +188,7 @@ public String getHTMLStats() {
187188

188189
str.append("</td></tr>\n");
189190

190-
str.append("<tr><td colspan=\"2\">Blank/KML/HTML:</td><td colspan=\"3\">");
191+
str.append("<tr><th colspan=\"2\" scope=\"row\">Blank/KML/HTML:</th><td colspan=\"3\">");
191192
if(totalRequests > 0) {
192193
if(totalHits + totalMisses == 0) {
193194
str.append("100.0% of requests");
@@ -202,9 +203,10 @@ public String getHTMLStats() {
202203
}
203204
str.append("</td></tr>\n");
204205

205-
str.append("<tr><td colspan=\"5\"> </td></tr>");
206+
str.append("</tbody>");
207+
str.append("<tbody>");
206208

207-
str.append("<tr><td colspan=\"2\">Peak request rate:</td><td colspan=\"3\">");
209+
str.append("<tr><th colspan=\"2\" scope=\"row\">Peak request rate:</th><td colspan=\"3\">");
208210
if(totalRequests > 0) {
209211
str.append(formatRequests( (peakRequests * 1.0) / pollInterval));
210212
str.append(" ("+ServletUtils.formatTimestamp(peakRequestsTime)+") ");
@@ -213,7 +215,7 @@ public String getHTMLStats() {
213215
}
214216
str.append("</td></tr>\n");
215217

216-
str.append("<tr><td colspan=\"2\">Peak bandwidth:</td><td colspan=\"3\">");
218+
str.append("<tr><th colspan=\"2\" scope=\"row\">Peak bandwidth:</th><td colspan=\"3\">");
217219
if(totalRequests > 0) {
218220
str.append(formatBits((peakBytes * 8.0) / pollInterval));
219221
str.append(" ("+ServletUtils.formatTimestamp(peakRequestsTime)+") ");
@@ -222,9 +224,10 @@ public String getHTMLStats() {
222224
}
223225
str.append("</td></tr>\n");
224226

225-
str.append("<tr><td colspan=\"5\"> </td></tr>");
227+
str.append("</tbody>");
228+
str.append("<tbody>");
226229

227-
str.append("<tr><td>Interval</td><td>Requests</td><td>Rate</td><td>Bytes</td><td>Bandwidth</td></tr>\n");
230+
str.append("<tr><th scope=\"col\">Interval</th><th scope=\"col\">Requests</th><th scope=\"col\">Rate</th><th scope=\"col\">Bytes</th><th scope=\"col\">Bandwidth</th></tr>\n");
228231

229232
for(int i=0; i<intervals.length; i++) {
230233
if(runningTime < intervals[i]) {
@@ -244,13 +247,17 @@ public String getHTMLStats() {
244247
+"</tr>\n");
245248
}
246249

247-
str.append("<tr><td colspan=\"5\"> </td></tr>");
250+
str.append("</tbody>");
251+
str.append("<tbody>");
248252

249253
str.append("<tr><td colspan=\"5\">All figures are "+pollInterval+" second(s) delayed and do not include HTTP overhead</td></tr>");
250254

251255
str.append("<tr><td colspan=\"5\">The cache hit ratio does not account for metatiling</td></tr>");
256+
257+
str.append("</tbody>");
258+
252259
}
253-
260+
254261
return str.toString();
255262
}
256263

@@ -305,11 +312,11 @@ private String formatBits(double bitsps) {
305312
String avg;
306313

307314
if(bitsps > 1000000) {
308-
avg = (Math.round(bitsps / 100000.0) / 10.0) + " mbps";
315+
avg = (Math.round(bitsps / 100000.0) / 10.0) + "&nbsp;mbps";
309316
} else if(bitsps > 1000) {
310-
avg = (Math.round(bitsps / 100.0) / 10.0) + " kbps";
317+
avg = (Math.round(bitsps / 100.0) / 10.0) + "&nbsp;kbps";
311318
} else {
312-
avg = (Math.round(bitsps * 10.0) / 10.0) + " bps";
319+
avg = (Math.round(bitsps * 10.0) / 10.0) + "&nbsp;bps";
313320
}
314321

315322
return avg;

geowebcache/core/src/main/java/org/geowebcache/util/ServletUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,14 @@ private static String[] URLDecode(String[] values, String encoding) {
395395

396396
public static String gwcHtmlHeader(String pageTitle) {
397397
return "<head>\n" + "<title>" + pageTitle + "</title>" + "<style type=\"text/css\">\n"
398-
+ "body, td {\n"
398+
+ "body, td, th {\n"
399399
+ "font-family: Verdana,Arial,\'Bitstream Vera Sans\',Helvetica,sans-serif;\n"
400-
+ "font-size: 0.85em;\n" + "vertical-align: top;\n" + "}\n" + "</style>\n"
400+
+ "font-size: 0.85em;\n" + "vertical-align: top;\n" + "}\n"
401+
+ "table.stats tbody + tbody tr * {padding-top: 1em;}\n"
402+
+ "table.stats tbody + tbody tr + tr * {padding-top: inherit;}\n"
403+
+ "table.stats th[scope=row] {text-align: right}\n"
404+
+ "table.stats th[scope=col] {text-align: left}\n"
405+
+ "</style>\n"
401406
+ "</head>\n";
402407
}
403408

0 commit comments

Comments
 (0)