use of lucee.runtime.monitor.IntervallMonitor in project Lucee by lucee.
the class XMLConfigWebFactory method loadMonitors.
private static void loadMonitors(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws IOException {
// only load in server context
if (configServer != null)
return;
configServer = (ConfigServerImpl) config;
Element parent = getChildByName(doc.getDocumentElement(), "monitoring");
boolean enabled = Caster.toBooleanValue(getAttr(parent, "enabled"), false);
configServer.setMonitoringEnabled(enabled);
SystemOut.printDate(config.getOutWriter(), "monitoring is " + (enabled ? "enabled" : "disabled"));
Element[] children = getChildren(parent, "monitor");
java.util.List<IntervallMonitor> intervalls = new ArrayList<IntervallMonitor>();
java.util.List<RequestMonitor> requests = new ArrayList<RequestMonitor>();
java.util.List<MonitorTemp> actions = new ArrayList<MonitorTemp>();
String strType, name;
ClassDefinition cd;
boolean log, async;
short type;
for (int i = 0; i < children.length; i++) {
Element el = children[i];
cd = getClassDefinition(el, "", config.getIdentification());
strType = getAttr(el, "type");
name = getAttr(el, "name");
async = Caster.toBooleanValue(getAttr(el, "async"), false);
log = Caster.toBooleanValue(getAttr(el, "log"), true);
if ("request".equalsIgnoreCase(strType))
type = IntervallMonitor.TYPE_REQUEST;
else if ("action".equalsIgnoreCase(strType))
type = Monitor.TYPE_ACTION;
else
type = IntervallMonitor.TYPE_INTERVAL;
if (cd.hasClass() && !StringUtil.isEmpty(name)) {
name = name.trim();
try {
Class clazz = cd.getClazz();
Object obj;
ConstructorInstance constr = Reflector.getConstructorInstance(clazz, new Object[] { configServer }, null);
if (constr != null)
obj = constr.invoke();
else
obj = clazz.newInstance();
SystemOut.printDate(config.getOutWriter(), "loaded " + (strType) + " monitor [" + clazz.getName() + "]");
if (type == IntervallMonitor.TYPE_INTERVAL) {
IntervallMonitor m = obj instanceof IntervallMonitor ? (IntervallMonitor) obj : new IntervallMonitorWrap(obj);
m.init(configServer, name, log);
intervalls.add(m);
} else if (type == Monitor.TYPE_ACTION) {
ActionMonitor am = obj instanceof ActionMonitor ? (ActionMonitor) obj : new ActionMonitorWrap(obj);
actions.add(new MonitorTemp(am, name, log));
} else {
RequestMonitorPro m = new RequestMonitorProImpl(obj instanceof RequestMonitor ? (RequestMonitor) obj : new RequestMonitorWrap(obj));
if (async)
m = new AsyncRequestMonitor(m);
m.init(configServer, name, log);
SystemOut.printDate(config.getOutWriter(), "initialize " + (strType) + " monitor [" + clazz.getName() + "]");
requests.add(m);
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
SystemOut.printDate(config.getErrWriter(), ExceptionUtil.getStacktrace(t, true));
}
}
}
configServer.setRequestMonitors(requests.toArray(new RequestMonitor[requests.size()]));
configServer.setIntervallMonitors(intervalls.toArray(new IntervallMonitor[intervalls.size()]));
ActionMonitorCollector actionMonitorCollector = ActionMonitorFatory.getActionMonitorCollector(configServer, actions.toArray(new MonitorTemp[actions.size()]));
configServer.setActionMonitorCollector(actionMonitorCollector);
((CFMLEngineImpl) configServer.getCFMLEngine()).touchMonitor(configServer);
}
use of lucee.runtime.monitor.IntervallMonitor in project Lucee by lucee.
the class Admin method doGetMonitors.
private void doGetMonitors() throws PageException {
if (!(config instanceof ConfigServerImpl))
throw new ApplicationException("invalid context for this action");
ConfigServerImpl cs = (ConfigServerImpl) config;
IntervallMonitor[] intervalls = cs.getIntervallMonitors();
RequestMonitor[] requests = cs.getRequestMonitors();
lucee.runtime.type.Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._name, KeyConstants._type, LOG_ENABLED, CLASS }, 0, "monitors");
doGetMonitors(qry, intervalls);
doGetMonitors(qry, requests);
pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Aggregations