Added health viewer (aka status) to Root prototype

This commit is contained in:
Tobi Schäfer 2008-05-14 12:25:15 +00:00
parent ae694946fa
commit 096f7ef572
3 changed files with 100 additions and 0 deletions

View file

@ -133,6 +133,7 @@ function scheduler() {
flushLog();
Stories.flushRequests();
helma.Mail.flushQueue();
Root.updateHealth();
// FIXME: root.manage.autoCleanUp();
// FIXME: pingUpdatedSites();
// FIXME: countUsers();

View file

@ -33,6 +33,67 @@ was not found on this server!</p>
<p>An error occurred while processing your request:</p>
<% param.error %>
<% #health %>
<p class="storyTitle"><% response.title %></p>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<colgroup>
<col width="60%" />
<col width="*" />
</colgroup>
<tr>
<td>Uptime</td>
<td><% param.uptime suffix=" d" %></td>
</tr>
<tr>
<td>Active threads</td>
<td><% param.activeThreads %></td>
</tr>
<tr>
<td>Free threads</td>
<td><% param.freeThreads %></td>
</tr>
<tr>
<td>Number of requests (last 5 min)</td>
<td><% param.requestsPerUnit %></td>
</tr>
<tr>
<td>Total requests</td>
<td><% param.requestCount %></td>
</tr>
<tr>
<td>Number of errors (last 5 min)</td>
<td><% param.errorsPerUnit %></td>
</tr>
<tr>
<td>Total errors</td>
<td><% param.errorCount %></td>
</tr>
<tr>
<td>Total XML-RPC requests</td>
<td><% param.xmlrpcCount %></td>
</tr>
<tr>
<td>Cached objects</td>
<td><% param.cacheusage %> of <% property cacheSize %></td>
</tr>
<tr>
<td>Number of sessions</td>
<td><% param.sessions %></td>
</tr>
<tr>
<td>Free memory</td>
<td><% param.freeMemory suffix=" MB" %></td>
</tr>
<tr>
<td>Used memory</td>
<td><% param.usedMemory suffix=" MB" %></td>
</tr>
<tr>
<td>Total memory</td>
<td><% param.totalMemory suffix=" MB" %></td>
</tr>
</table>

View file

@ -50,6 +50,17 @@ Root.restore = function(ref) {
return ref;
}
Root.updateHealth = function() {
var health = Root.health || {};
if (!health.modified || new Date - health.modified > 5 * Date.ONEMINUTE) {
health.modified = new Date;
health.totalRequests = app.requestCount;
health.totalErrors = app.errorCount;
Root.health = health;
}
return;
}
Root.prototype.processHref = function(href) {
return app.properties.defaulthost + href;
}
@ -61,6 +72,7 @@ Root.prototype.getPermission = function(action) {
switch (action) {
case "backup.js":
case "debug":
case "health":
return true;
case "create":
return this.getCreationPermission();
@ -237,6 +249,32 @@ Root.prototype.updates_xml_action = function() {
return;
}
Root.prototype.health_action = function() {
var param = {};
var properties = ["activeThreads", "freeThreads", "requestCount",
"errorCount", "xmlrpcCount", "cacheusage"];
for each (var key in properties) {
param[key] = app[key];
}
var jvm = java.lang.Runtime.getRuntime();
var totalMemory = jvm.totalMemory() / 1024 / 1024;
var freeMemory = jvm.freeMemory() / 1024 / 1024;
param.freeMemory = freeMemory.format();
param.totalMemory = totalMemory.format();
param.usedMemory = (totalMemory - freeMemory).format("0.##");
param.uptime = ((new Date - app.upSince.getTime()) /
Date.ONEDAY).format("0.##");
param.sessions = app.countSessions();
param.requestsPerUnit = param.requestCount - Root.health.totalRequests;
param.errorsPerUnit = param.errorCount - Root.health.totalErrors;
res.data.title = "Health of " + root.getTitle();
res.data.body = this.renderSkinAsString("$Root#health", param);
this.renderSkin("Site#page");
}
Root.prototype.getMacroHandler = function(name) {
switch (name) {
case "sites":