/** * Count the thrown exception and put the stack trace in the details portion of the key. * This will allow the stack trace to be viewed in the JAMon web application. */ protected void trackException(MonKey key, Throwable ex) { String stackTrace = "stackTrace=" + Misc.getExceptionTrace(ex); key.setDetails(stackTrace); // Specific exception counter. Example: java.lang.RuntimeException MonitorFactory.add(new MonKeyImp(ex.getClass().getName(), stackTrace, "Exception"), 1); // General exception counter which is a total for all exceptions thrown MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTrace, "Exception"), 1); }
private void calculateDurationAndAddToMonitor() { if (this.startTimeRequest != 0 && !dontMonitorThisRequest) { long duration = System.currentTimeMillis() - startTimeRequest; if (includeSourceNameInMonitorLabel) { MonitorFactory.add(createLabel(), UNIT, duration); } else { MonitorFactory.add(String.format("%s", target), UNIT, duration); } } }
public void addMonitor() throws Exception { System.out.println("Calling add...\n"); System.out.println("\tMonitorFactory.add('label','units',1);"); for (int i=0; i<testIterations; i++) { MonitorFactory.add("label","units",1); } System.out.println(MonitorFactory.getMonitor("label", "units")); }
public void addMonitor() throws Exception { System.out.println("Calling add...\n"); System.out.println("\tMonitorFactory.add('label','units',1);"); for (int i=0; i<testIterations; i++) { MonitorFactory.add("label","units",1); } System.out.println(MonitorFactory.getMonitor("label", "units")); }
private void monitorDuration(String labelPrefix, String details) { MonKey key = new MonKeyImp(labelPrefix+".time", details, "ms."); MonitorFactory.add(key, duration); // ms. duration of gc }
private void trackException(Throwable rootCause, Method method, String sqlMessage) { String detailStackTrace = Misc.getExceptionTrace(rootCause); MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, detailStackTrace, "Exception"), 1); // counts total exceptions from jamon MonitorFactory.add(new MonKeyImp("MonProxy-Exception: InvocationTargetException", detailStackTrace, "Exception"), 1); //counts total exceptions for MonProxy MonitorFactory.add(new MonKeyImp("MonProxy-Exception: Root cause exception="+rootCause.getClass().getName()+sqlMessage, detailStackTrace, "Exception"), 1); // Message for the exception MonitorFactory.add(new MonKeyImp(labelerInt.getExceptionLabel(method), detailStackTrace,"Exception"), 1); // Exception and method that threw it. }
private static Driver registerDriver(String className) throws SQLException { Driver d=null; try { d=(Driver) Class.forName(className).newInstance(); DriverManager.registerDriver(d); } catch (Exception e){ String message="MonProxy-Exception: loading JDBC Driver="+e.getMessage(); MonitorFactory.add(new MonKeyImp(message, e.getMessage(), "Exception"),1); // MonitorFactory.add(message, "Exception",1); DriverManager.println(message); throw new SQLException("Can not load real driver ("+className+") from JAMonDriver: "+e.getLocalizedMessage()); } return d; }
/** * Count the thrown exception and put the stack trace in the details portion of the key. * This will allow the stack trace to be viewed in the JAMon web application. */ protected void trackException(MonKey key, Throwable ex) { String stackTrace = "stackTrace=" + Misc.getExceptionTrace(ex); key.setDetails(stackTrace); // Specific exception counter. Example: java.lang.RuntimeException MonitorFactory.add(new MonKeyImp(ex.getClass().getName(), stackTrace, "Exception"), 1); // General exception counter which is a total for all exceptions thrown MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTrace, "Exception"), 1); }
/** * Count the thrown exception and put the stack trace in the details portion of the key. * This will allow the stack trace to be viewed in the JAMon web application. */ protected void trackException(MonKey key, Throwable ex) { String stackTrace = "stackTrace=" + Misc.getExceptionTrace(ex); key.setDetails(stackTrace); // Specific exception counter. Example: java.lang.RuntimeException MonitorFactory.add(new MonKeyImp(ex.getClass().getName(), stackTrace, "Exception"), 1); // General exception counter which is a total for all exceptions thrown MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTrace, "Exception"), 1); }
private static Driver registerDriver(String className) throws SQLException { Driver d=null; try { d=(Driver) Class.forName(className).newInstance(); DriverManager.registerDriver(d); } catch (Exception e){ String message="MonProxy-Exception: loading JDBC Driver="+e.getMessage(); MonitorFactory.add(new MonKeyImp(message, new Object[]{message, Misc.getExceptionTrace(e)}, "Exception"),1); DriverManager.println(message); throw new SQLException("Can not load real driver ("+className+") from JAMonDriver: "+e.getLocalizedMessage()); } return d; }
/** * Loop through different memory pools and determine how much memory is used (bytes) after this * gc firing. Example data follows: * * before: PS Survivor Space=... used = 1589320(1552K)..., * after: PS Survivor Space=... used = 0(0K)... * * @param labelPrefix * @param gcInfo * @param details */ private void monitorUsedMemory(String labelPrefix, GcInfo gcInfo, String details) { for (Map.Entry<String, MemoryUsage> entry : gcInfo.getMemoryUsageAfterGc().entrySet()) { MonKey key = new MonKeyImp(labelPrefix+".usedMemory."+entry.getKey(), details, "bytes"); MonitorFactory.add(key, entry.getValue().getUsed()); // memory used in pool. } }
/** Note this creates 2 exception monitors and the more specific one is returned */ @Override public Monitor addException(Monitor mon, Throwable throwable) { String stackTtrace = new StringBuffer("stackTrace=") .append(Misc.getExceptionTrace(throwable)) .toString(); if (mon!=null) { MonKey key = mon.getMonKey(); key.setDetails(stackTtrace); } MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTtrace, "Exception"), 1); return MonitorFactory.add(new MonKeyImp(throwable.getClass().getName(), stackTtrace, "Exception"), 1); }
private void createSizeThresholdExceededMon(HttpMonRequest httpMonBase) { String label=new StringBuffer(httpMonBase.getLabelPrefix()).append(".HttpMonFactory.sizeExceeded.").append(httpMonBase.getSize()).toString(); String detailLabel=new StringBuffer(getLabel(httpMonBase)).append(", ").append(httpMonBase.getRequestURI()).append(", ").append(getUnits()).toString(); MonitorFactory.add(new MonKeyImp(label, detailLabel, "Count"), httpMonBase.getSize()); }
/** process calls to add which is an implemetation of a counter or adder. */ private void add(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter out = response.getWriter(); String label=request.getParameter("add"); // jamon label String units=request.getParameter("units"); // something like bytes String value=request.getParameter("value"); // number String detail=request.getParameter("detail"); // can view via jamon listeners. Double val=toDouble(value); if (isEmpty(label) || isEmpty(units) || isEmpty(val)) { out.println(ERROR+": add requires that a label, units and numeric value are passed in. For example: curl http://localhost:8080/jamon/Mon?add=mylabel&units=bytes&value=1234"); out.println(" Optionally a detail may be passed in: curl http://localhost:8080/jamon/Mon?add=os.mylabel&units=bytes&value=1234&detail=Backup%20script%20from%20host%20backupserver\n"); } else { MonKey key=getMonKey(label, detail, units); Monitor mon=MonitorFactory.add(key, val); out.println(OK+": add successfully called on - "+label+" - "+mon); } }
@Override protected void trackException(JoinPoint jp, Throwable throwable) { AutomonExpirable exceptionContext = populateArgNamesAndValues_InExceptionContext(jp, throwable); // Multiple monitors are tracked for the exception such as one of the specific exception and one that represents // all exceptions. List<String> labels = getLabels(throwable); for (String label : labels) { MonKey key = new MonKeyImp(label, exceptionContext, "Exception"); MonitorFactory.add(key, 1); } }
@Override protected void trackException(JoinPoint jp, Throwable throwable) { AutomonExpirable exceptionContext = populateArgNamesAndValues_InExceptionContext(jp, throwable); // Multiple monitors are tracked for the exception such as one of the specific exception and one that represents // all exceptions. List<String> labels = getLabels(throwable); for (String label : labels) { MonKey key = new MonKeyImp(label, exceptionContext, "Exception"); MonitorFactory.add(key, 1); } }
private void setException() { if (requestException==null && request instanceof HttpServletRequest) { Object exc=((HttpServletRequest)request).getAttribute(EXCEPTION_ATTR);// defined by all containers if (exc instanceof Throwable) setException((Throwable)exc);//sets requestException } // if an exception has occurred make neccesarry jamon records. if (requestException!=null) { StringBuffer trace=new StringBuffer("stackTrace=").append(Misc.getExceptionTrace(requestException)); if (requestException instanceof ServletException && ((ServletException)requestException).getRootCause()!=null) trace.append("\nrootCause=").append(Misc.getExceptionTrace(((ServletException)requestException).getRootCause())); setStackTrace(trace.toString()); String label=getLabelPrefix()+".ServletException"; MonitorFactory.add(new MonKeyImp(label, getDetailLabel(), "Exception"), 1); MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, getDetailLabel(), "Exception"), 1); } }
private Object executeMethod(HttpMonRequest httpMonBase) { Object retValue=null; try { retValue = getMethod(httpMonBase).invoke(getObjectToExecute(httpMonBase), (Object[])null);// null is noargs. } catch (Throwable e) {// note I don't want the program to abort due to monitoring so the exception is not being passed upstream MonitorFactory.add(new MonKeyImp(httpMonBase.getLabelPrefix()+".monError", new Object[]{this, Misc.getExceptionTrace(e)}, "Exception"),1); } return retValue; }
void stop(HttpMonRequest httpMonBase) { if (isTimeMon) { stopTimeMon(httpMonBase); } else if (sizeThresholdExceeded(httpMonBase)) {// note thresholds indicators have already been created for time monitors createSizeThresholdExceededMon(httpMonBase); } else { MonitorFactory.add(getMonKey(httpMonBase), getValueToAdd(httpMonBase)); } }