From 096f7ef572e0e2460cf6ff0ef9c9faef86941bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobi=20Sch=C3=A4fer?= Date: Wed, 14 May 2008 12:25:15 +0000 Subject: [PATCH] Added health viewer (aka status) to Root prototype --- code/Global/Global.js | 1 + code/Root/$Root.skin | 61 +++++++++++++++++++++++++++++++++++++++++++ code/Root/Root.js | 38 +++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/code/Global/Global.js b/code/Global/Global.js index 8ad0edb2..fa198584 100644 --- a/code/Global/Global.js +++ b/code/Global/Global.js @@ -133,6 +133,7 @@ function scheduler() { flushLog(); Stories.flushRequests(); helma.Mail.flushQueue(); + Root.updateHealth(); // FIXME: root.manage.autoCleanUp(); // FIXME: pingUpdatedSites(); // FIXME: countUsers(); diff --git a/code/Root/$Root.skin b/code/Root/$Root.skin index a6adef00..2eec0013 100644 --- a/code/Root/$Root.skin +++ b/code/Root/$Root.skin @@ -33,6 +33,67 @@ was not found on this server!

An error occurred while processing your request:

<% param.error %> +<% #health %> +

<% response.title %>

+ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Uptime<% param.uptime suffix=" d" %>
Active threads<% param.activeThreads %>
Free threads<% param.freeThreads %>
Number of requests (last 5 min)<% param.requestsPerUnit %>
Total requests<% param.requestCount %>
Number of errors (last 5 min)<% param.errorsPerUnit %>
Total errors<% param.errorCount %>
Total XML-RPC requests<% param.xmlrpcCount %>
Cached objects<% param.cacheusage %> of <% property cacheSize %>
Number of sessions<% param.sessions %>
Free memory<% param.freeMemory suffix=" MB" %>
Used memory<% param.usedMemory suffix=" MB" %>
Total memory<% param.totalMemory suffix=" MB" %>
+ diff --git a/code/Root/Root.js b/code/Root/Root.js index f341e7cc..a54c78d7 100644 --- a/code/Root/Root.js +++ b/code/Root/Root.js @@ -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":