-
+
+
+
+
-
+
-
+
@@ -26,10 +50,11 @@
var nattrmonApp = angular.module('nattrmonApp', ['ngAnimate']);
var extra = "?";
if (getUrlParameter("ct") != "") extra = "?ct=" + getUrlParameter("ct");
+ var withBasePath = window.withBasePath;
nattrmonApp.service('MetaService', function($http) {
this.getMeta = function() {
- return $http.get('/meta').then(function(result) {
+ return $http.get(withBasePath('/meta')).then(function(result) {
return result;
});
};
@@ -37,7 +62,7 @@
nattrmonApp.service('JsonService', function($http) {
this.getJson = function() {
- return $http.get('/json' + extra).then(function(result) {
+ return $http.get(withBasePath('/json') + extra).then(function(result) {
return result;
});
};
@@ -175,7 +200,7 @@
@@ -203,7 +228,7 @@
- last value: @ (see more)
+ last value: @ (see more)
|
Last modify: Last check:
diff --git a/config/objects.assets/noutputhttp/plugs.html b/config/objects.assets/noutputhttp/plugs.html
index 6b34cd5..1b3b900 100644
--- a/config/objects.assets/noutputhttp/plugs.html
+++ b/config/objects.assets/noutputhttp/plugs.html
@@ -6,14 +6,38 @@
-
+
+
-
+
-
+
@@ -26,10 +50,11 @@
var nattrmonApp = angular.module('nattrmonApp', ['ngAnimate']);
var extra = "";
if (getUrlParameter("ct") != "") extra = "?ct=" + getUrlParameter("ct");
+ var withBasePath = window.withBasePath;
nattrmonApp.service('MetaService', function($http) {
this.getMeta = function() {
- return $http.get('/meta').then(function(result) {
+ return $http.get(withBasePath('/meta')).then(function(result) {
return result;
});
};
@@ -37,13 +62,13 @@
nattrmonApp.service('JsonService', function($http) {
this.getJson = function() {
- return $http.get('/json').then(function(result) {
+ return $http.get(withBasePath('/json')).then(function(result) {
return result;
});
};
this.getPlugs = function() {
- return $http.get('/json?op=plugs').then(function(result) {
+ return $http.get(withBasePath('/json') + '?op=plugs').then(function(result) {
return result;
});
}
@@ -188,13 +213,13 @@
diff --git a/config/objects/nInput_RAIDMemory.js b/config/objects/nInput_RAIDMemory.js
index 78430e2..9d5a447 100644
--- a/config/objects/nInput_RAIDMemory.js
+++ b/config/objects/nInput_RAIDMemory.js
@@ -7,6 +7,7 @@
* - attrTemplate (a template for the name of the attribute)\
* - single (boolean when false display the corresponding key)\
* - extra (an array of extra map values to include from the chKeys channel values)\
+ * - useCache (string cache name to use; or boolean true to enable with default cache name)\
* \
*
*/
@@ -28,6 +29,15 @@ var nInput_RAIDMemory = function(anMonitoredAFObjectKey, attributePrefix) {
if (isUnDef(this.params.attrTemplate))
this.params.attrTemplate = "Server status/Memory";
+
+ if (isUnDef(this.params.useCache) || this.params.useCache === false) {
+ this.params.useCache = false;
+ } else if (this.params.useCache === true) {
+ this.params.useCache = "memory";
+ } else if (!isString(this.params.useCache)) {
+ this.params.useCache = false;
+ logWarn("nInput_RAIDMemory | Parameter useCache must be a string (cache name) or boolean, setting it as false.");
+ }
this.params.extraMemoryDetails = _$(this.params.extraMemoryDetails).isBoolean().default(false)
if (this.params.extraMemoryDetails) {
@@ -64,11 +74,13 @@ nInput_RAIDMemory.prototype.__getMemory = function(aKey, aExtra) {
var usedmem = -1;
var maxmem = -1;
var totalmem = -1;
+ var gccoll = {};
+ var gcspace = {};
try {
var mems;
var parent = this;
- if (isString(parent.params.useCache)) {
+ if (parent.params.useCache) {
var res = $cache("nattrmon::" + parent.params.useCache + "::" + aKey).get({ op: "StatusReport", args: this._args })
if (isMap(res) && isDef(res.__error)) throw res.__error;
mems = res.MemoryInfo;
@@ -76,11 +88,10 @@ nInput_RAIDMemory.prototype.__getMemory = function(aKey, aExtra) {
var parent = this
nattrmon.useObject(aKey, function(s) {
try {
- mems = s.exec("StatusReport", parent._args).MemoryInfo
+ mems = s.exec("StatusReport", parent._args).MemoryInfo;
} catch(e) {
- logErr("Error while retrieving memory using '" + aKey + "': " + e.message);
throw e;
- }
+ }
});
}
@@ -88,14 +99,26 @@ nInput_RAIDMemory.prototype.__getMemory = function(aKey, aExtra) {
usedmem = Math.round(Number(mems.UsedHeapMemory.replace(/MB/,"")));
maxmem = Math.round(Number(mems.MaxMemory.replace(/MB/,"")));
totalmem = Math.round(Number(mems.TotalHeapMemory.replace(/MB/,"")));
+ if (parent.params.extraMemoryDetails) {
+ gccoll = mems.GCCollectors;
+ gcspace = mems.GCSpaces;
+ }
} catch(e) {
- logErr("Error while retrieving memory using '" + aKey + "': " + e.message);
+ logErr("nInput_RAIDMemory || Error while retrieving memory using '" + aKey + "': " + e.message);
}
if(!this.params.single) {
- ret = {"Free heap (MB)": freemem, "Used heap (MB)": usedmem, "Total heap (MB)": totalmem, "Max memory (MB)": maxmem, "GCCollectors": mems.GCCollectors, "GCSpaces": mems.GCSpaces};
+ ret = {"Free heap (MB)": freemem, "Used heap (MB)": usedmem, "Total heap (MB)": totalmem, "Max memory (MB)": maxmem};
+ if (parent.params.extraMemoryDetails) {
+ ret["GCCollectors"] = gccoll;
+ ret["GCSpaces"] = gcspace;
+ }
} else {
- ret = {"Name": aKey, "Free heap (MB)": freemem, "Used heap (MB)": usedmem, "Total heap (MB)": totalmem, "Max memory (MB)": maxmem, "GCCollectors": mems.GCCollectors, "GCSpaces": mems.GCSpaces};
+ ret = {"Name": aKey, "Free heap (MB)": freemem, "Used heap (MB)": usedmem, "Total heap (MB)": totalmem, "Max memory (MB)": maxmem};
+ if (parent.params.extraMemoryDetails) {
+ ret["GCCollectors"] = gccoll;
+ ret["GCSpaces"] = gcspace;
+ }
ret = merge(ret, aExtra);
}
diff --git a/config/objects/nOutput_HTTP.js b/config/objects/nOutput_HTTP.js
index 342cfe7..8a256fe 100644
--- a/config/objects/nOutput_HTTP.js
+++ b/config/objects/nOutput_HTTP.js
@@ -6,6 +6,16 @@ var nOutput_HTTP = function (aMap) {
var aPort = isDef(aMap.port) ? aMap.port : 8090;
var aRefreshTime = isDef(aMap.refreshTime) ? aMap.refreshTime : 2500;
var path = isDef(aMap.path) ? aMap.path : io.fileInfo(nattrmon.getConfigPath("objects.assets/noutputhttp")).canonicalPath;
+ var relativePath = _$(aMap.relativePath, "relativePath").isString().default(
+ isDef(__flags.HTTPD_PREFIX) && isDef(ow.server.httpd.stripPrefix)
+ ? (ow.server.httpd.getPrefix(aPort) || "/")
+ : "/"
+ );
+ relativePath = templify(relativePath);
+
+ if (!relativePath.startsWith("/")) relativePath = "/" + relativePath;
+ relativePath = relativePath.replace(/\/+$/, "");
+ if (relativePath == "") relativePath = "/";
this.audit = (isDef(aMap.audit) ? aMap.audit : true);
this.auditTemplate = (isDef(aMap.auditTemplate) ? aMap.auditTemplate : AUDIT_TEMPLATE);
@@ -114,20 +124,40 @@ var nOutput_HTTP = function (aMap) {
return res;
}
- // Add function to server
- ow.server.httpd.route(httpd, ow.server.httpd.mapWithExistingRoutes(httpd, ow.server.httpd.mapRoutesWithLibs(httpd, {
- "/f": function (r) {
+ var useNativePrefix = isDef(__flags.HTTPD_PREFIX) && isDef(ow.server.httpd.stripPrefix);
+ if (useNativePrefix && relativePath !== "/") __flags.HTTPD_PREFIX[String(aPort)] = relativePath;
+
+ var routePath = (!useNativePrefix && relativePath !== "/")
+ ? (aSuffix) => { if (aSuffix == "/") return relativePath; return relativePath + aSuffix; }
+ : (aSuffix) => aSuffix;
+
+ var stripBasePath = (!useNativePrefix && relativePath !== "/")
+ ? (aUri) => {
+ if (isUnDef(aUri)) return "/";
+ if (aUri === relativePath || aUri.startsWith(relativePath + "/")) {
+ var localUri = aUri.substring(relativePath.length);
+ return (localUri == "") ? "/" : localUri;
+ }
+ return aUri;
+ }
+ : (aUri) => isUnDef(aUri) ? "/" : aUri;
+
+ var routes = {};
+
+ routes[routePath("/f")] = function (r) {
try {
- if (r.uri == "/f") r.uri = "/index.html"
- var hres = ow.server.httpd.replyFile(httpd, path + "/objects.assets/noutputhttp", "/f", r.uri)
+ var localUri = stripBasePath(r.uri);
+ if (localUri == "/f") localUri = "/index.html"
+ var hres = ow.server.httpd.replyFile(httpd, path + "/objects.assets/noutputhttp", "/f", localUri)
return preProcess(r, hres)
} catch(e) {
logErr("nOutput_HTTP | Error in HTTP request: " + stringify(r, __, "") + "; exception: " + String(e))
if (isJavaException(e)) e.javaException.printStackTrace()
return ow.server.httpd.reply("Error (check logs)", 500)
}
- },
- "/meta": function (req) {
+ };
+
+ routes[routePath("/meta")] = function (req) {
try {
var ret = {}
ret = nattrmon.getSessionData("httpd.summary.custom")
@@ -139,22 +169,29 @@ var nOutput_HTTP = function (aMap) {
if (isJavaException(e)) e.javaException.printStackTrace()
return ow.server.httpd.reply("Error (check logs)", 500)
}
- },
- "/": function (r) {
+ };
+
+ routes[routePath("/")] = function (r) {
try {
- if (r.uri == "/") r.uri = "/index.html"
- var hres = ow.server.httpd.replyFile(httpd, path + "/objects.assets/noutputhttp", "/", r.uri)
+ var localUri = stripBasePath(r.uri);
+ if (localUri == "/") localUri = "/index.html"
+ var hres = ow.server.httpd.replyFile(httpd, path + "/objects.assets/noutputhttp", "/", localUri)
return preProcess(r, hres)
} catch(e) {
logErr("nOutput_HTTP | Error in HTTP request: " + stringify(r, __, "") + "; exception: " + String(e))
if (isJavaException(e)) e.javaException.printStackTrace()
return ow.server.httpd.reply("Error (check logs)", 500)
}
- }
- }), function (r) {
+ };
+
+ if (!useNativePrefix && relativePath !== "/") routes[relativePath + "/"] = routes[routePath("/")];
+
+ // Add function to server
+ ow.server.httpd.route(httpd, ow.server.httpd.mapWithExistingRoutes(httpd, ow.server.httpd.mapRoutesWithLibs(httpd, routes), function (r) {
try {
- if (r.uri == "/") r.uri = "/index.html";
- var hres = ow.server.httpd.replyFile(httpd, path + "/objects.assets/noutputhttp", "/", r.uri);
+ var localUri = stripBasePath(r.uri);
+ if (localUri == "/") localUri = "/index.html";
+ var hres = ow.server.httpd.replyFile(httpd, path + "/objects.assets/noutputhttp", "/", localUri);
return preProcess(r, hres);
} catch(e) {
logErr("nOutput_HTTP | Error in HTTP request: " + stringify(r, __, "") + "; exception: " + String(e))
@@ -173,7 +210,7 @@ var nOutput_HTTP = function (aMap) {
if (isJavaException(e)) e.javaException.printStackTrace()
}
- log("Output_HTTP | Output HTTP created on " + aPort);
+ log("Output_HTTP | Output HTTP created on " + aPort + " with relativePath '" + relativePath + "'");
nOutput.call(this, this.output);
};
diff --git a/config/objects/nOutput_HTTP_JSON.js b/config/objects/nOutput_HTTP_JSON.js
index e426490..70535d9 100644
--- a/config/objects/nOutput_HTTP_JSON.js
+++ b/config/objects/nOutput_HTTP_JSON.js
@@ -12,6 +12,16 @@ var nOutput_HTTP_JSON = function (aMap) {
this.audit = true;
this.auditTemplate = AUDIT_TEMPLATE;
}
+
+ var relativePath = _$(aMap.relativePath, "relativePath").isString().default(
+ isDef(__flags.HTTPD_PREFIX) && isDef(ow.server.httpd.stripPrefix)
+ ? (ow.server.httpd.getPrefix(aPort) || "/")
+ : "/"
+ );
+ relativePath = templify(relativePath);
+ if (!relativePath.startsWith("/")) relativePath = "/" + relativePath;
+ relativePath = relativePath.replace(/\/+$/, "");
+ if (relativePath == "") relativePath = "/";
var hauth_perms, hauth_func;
var hauth_type = _$(aMap.authType, "hauthType").isString().default("none");
@@ -110,10 +120,18 @@ var nOutput_HTTP_JSON = function (aMap) {
return res;
}
+ var useNativePrefix = isDef(__flags.HTTPD_PREFIX) && isDef(ow.server.httpd.stripPrefix);
+ if (useNativePrefix && relativePath !== "/") __flags.HTTPD_PREFIX[String(aPort)] = relativePath;
+
+ var routePath = (!useNativePrefix && relativePath !== "/")
+ ? (aSuffix) => { if (aSuffix == "/") return relativePath; return relativePath + aSuffix; }
+ : (aSuffix) => aSuffix;
+
+ var routes = {};
+
// Add function to server
//httpd.addEcho("/echo");
- ow.server.httpd.route(httpd, ow.server.httpd.mapWithExistingRoutes(httpd, {
- "/json": function (req) {
+ routes[routePath("/json")] = function (req) {
try {
switch (req.params.op) {
case "histtime":
@@ -164,8 +182,9 @@ var nOutput_HTTP_JSON = function (aMap) {
if (isJavaException(e)) e.javaException.printStackTrace()
return ow.server.httpd.reply("Error (check logs)", 500)
}
- }
- }), function (r) {
+ };
+
+ ow.server.httpd.route(httpd, ow.server.httpd.mapWithExistingRoutes(httpd, routes), function (r) {
try {
var hres = httpd.replyOKJSON(stringify({}));
return preProcess(r, hres);
@@ -176,6 +195,8 @@ var nOutput_HTTP_JSON = function (aMap) {
}
});
+ log("Output_HTTP_JSON | Output HTTP JSON created on " + aPort + " with relativePath '" + relativePath + "'");
+
nOutput.call(this, this.output);
};
inherit(nOutput_HTTP_JSON, nOutput);
diff --git a/config/objects/nOutput_HTTP_Metrics.js b/config/objects/nOutput_HTTP_Metrics.js
index 8288081..ef7a2a7 100644
--- a/config/objects/nOutput_HTTP_Metrics.js
+++ b/config/objects/nOutput_HTTP_Metrics.js
@@ -184,6 +184,16 @@ var nOutput_HTTP_Metrics = function (aMap) {
aMap = {};
}
+ var relativePath = _$(aMap.relativePath, "relativePath").isString().default(
+ isDef(__flags.HTTPD_PREFIX) && isDef(ow.server.httpd.stripPrefix)
+ ? (ow.server.httpd.getPrefix(aPort) || "/")
+ : "/"
+ );
+ relativePath = templify(relativePath);
+ if (!relativePath.startsWith("/")) relativePath = "/" + relativePath;
+ relativePath = relativePath.replace(/\/+$/, "");
+ if (relativePath == "") relativePath = "/";
+
var hauth_perms, hauth_func;
var hauth_type = _$(aMap.authType, "hauthType").isString().default("none");
if (isDef(aMap.auth)) hauth_perms = aMap.auth;
@@ -396,11 +406,30 @@ var nOutput_HTTP_Metrics = function (aMap) {
return lines
}
+ var useNativePrefix = isDef(__flags.HTTPD_PREFIX) && isDef(ow.server.httpd.stripPrefix);
+ if (useNativePrefix && relativePath !== "/") __flags.HTTPD_PREFIX[String(aPort)] = relativePath;
+
+ var routePath = (!useNativePrefix && relativePath !== "/")
+ ? (aSuffix) => { if (aSuffix == "/") return relativePath; return relativePath + aSuffix; }
+ : (aSuffix) => aSuffix;
+
+ var stripBasePath = (!useNativePrefix && relativePath !== "/")
+ ? (aUri) => {
+ if (isUnDef(aUri)) return "/";
+ if (aUri === relativePath || aUri.startsWith(relativePath + "/")) {
+ var localUri = aUri.substring(relativePath.length);
+ return (localUri == "") ? "/" : localUri;
+ }
+ return aUri;
+ }
+ : (aUri) => isUnDef(aUri) ? "/" : aUri;
+
+ var routes = {};
+
// Add function to server
//httpd.addEcho("/echo");
var parent = this;
- ow.server.httpd.route(httpd, ow.server.httpd.mapWithExistingRoutes(httpd, {
- "/metrics": function (req) {
+ routes[routePath("/metrics")] = function (req) {
try {
var res = "";
var fmt = _$(req.params.format).default(parent.format)
@@ -452,17 +481,20 @@ var nOutput_HTTP_Metrics = function (aMap) {
if (isJavaException(e)) e.javaException.printStackTrace()
return ow.server.httpd.reply("Error (check logs)", 500)
}
- }
- }), function (r) {
+ };
+
+ ow.server.httpd.route(httpd, ow.server.httpd.mapWithExistingRoutes(httpd, ow.server.httpd.mapRoutesWithLibs(httpd, routes), function (r) {
try {
+ var localUri = stripBasePath(r.uri);
var hres = ow.server.httpd.reply("", 200, "text/plain", {});
+ if (localUri == "/") hres.data = "";
return preProcess(r, hres);
} catch(e) {
logErr("Error in HTTP request: " + stringify(r, __, "") + "; exception: " + String(e))
if (isJavaException(e)) e.javaException.printStackTrace()
return ow.server.httpd.reply("Error (check logs)", 500)
}
- });
+ }));
nOutput.call(this, this.output);
};
|