/** * 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); }
@Override public String getDetails(ProceedingJoinPoint proceedingJoinPoint, Throwable exception) { return new StringBuffer("stackTrace=") .append(Misc.getExceptionTrace(exception)) .toString(); }
private void addExceptionStackTraceToDetails(StringBuilder temp,Exception exception) { if(exception != null) { temp.append("=== Stack Trace ===").append(LINE_SEPARATOR); temp.append(Misc.getExceptionTrace(exception)); } }
private static String getArrAsString(Object[] arr) { int lastElement=arr.length-1; StringBuffer buff=new StringBuffer(); for (int i=0;i<arr.length;i++) { Object obj=arr[i]; if (obj instanceof Throwable) obj=getExceptionTrace((Throwable)obj); buff.append(obj); if (i!=lastElement) buff.append(",\n"); } return buff.toString(); }
private static String getCollAsString(Collection coll) { int currentElement=1; int lastElement=coll.size(); Iterator iter=coll.iterator(); StringBuffer buff=new StringBuffer(); // loop through elements creating a comma delimeted list of the values while(iter.hasNext()) { Object obj=iter.next(); if (obj instanceof Throwable) obj=getExceptionTrace((Throwable)obj); buff.append(obj); if (currentElement!=lastElement) buff.append(",\n"); currentElement++; } return buff.toString(); }
/** Create details for when an exception is thrown. This would be the stack trace and possibly the methods * arguments if useArgsWithExceptionDetails has been set. * * @param proceedingJoinPoint * @param exception * @return */ @Override public String getDetails(ProceedingJoinPoint proceedingJoinPoint, Throwable exception) { String detailMessage = createDetailMessage(proceedingJoinPoint, "", useArgsWithExceptionDetails); String stackTrace = new StringBuffer(detailMessage) .append("\n\nstackTrace=") .append(Misc.getExceptionTrace(exception)) .toString(); return stackTrace; }
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; }
/** 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); }
/** * 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 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; }
String detailStackTrace=Misc.getExceptionTrace(rootCause); MonitorFactory.add( new MonKeyImp( "MonProxy-Exception: InvocationTargetException", params.exceptionBuffer.addRow(new Object[] { new Long(++params.exceptionID), new Date(), Misc.getExceptionTrace(rootCause), method.toString(), });
public static String getAsString(Object obj) { try { if (obj==null) return null; else if (obj instanceof Collection) return getCollAsString((Collection)obj); else if (obj instanceof Object[]) return getArrAsString((Object[]) obj); else if (obj instanceof ToArray) return getArrAsString(((ToArray)obj).toArray()); else if (obj instanceof Throwable) return getExceptionTrace((Throwable)obj); else return obj.toString(); } catch(Throwable e) { // ignore any exception here since return "???"; } }
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. }
/** * @see java.sql.Driver#connect(java.lang.String, java.util.Properties) */ public Connection connect(String url, Properties info) throws SQLException { if (!acceptsURL(url)) return null; // use jamonrealdriver from properties if it is there. URLInfo urlInfo=new URLInfo(url, info); Driver realDriver=getRegisteredDriver(urlInfo.getRealURL()); if (realDriver==null) { // for example: com.sybase.jdbc2.jdbc.SybDriver realDriver=registerDriver(urlInfo.getRealDriverName()); } Monitor mon = MonitorFactory.start("MonProxy-Interface (class=com.jamonapi.proxy.JAMonDriver): public java.sql.Connection com.jamonapi.proxy.JAMonDriver.connect(java.lang.String, java.util.Properties) throws java.sql.SQLException"); Connection conn=null; try { conn=MonProxyFactory.monitor(realDriver.connect(urlInfo.getRealURL(), info)); } catch (SQLException sqlException) { String sqlMessage=",ErrorCode="+sqlException.getErrorCode()+",SQLState="+sqlException.getSQLState(); String label="MonProxy-Exception: Root cause exception="+sqlException.getClass().getName()+sqlMessage; MonKey key=new MonKeyImp(label, new Object[]{label, Misc.getExceptionTrace(sqlException)}, "Exception"); MonitorFactory.add(key,1); // Message for the exception throw sqlException; } finally { mon.stop(); } // call the following method just in case the realDriver returns a proxied connection itself. return conn; }
/** * method that returns an array to use in the Buffer. It can return any * sortable objects as long as they match what is returned in the * getHeader() method. * * @param event * @param mon * @return Object[] */ protected Object[] toArray(LoggingEvent event, Monitor mon) { // populate header with standard monitor data first and after the fact by log4j data Object[] data=log4jHeader.getData(mon); data[0]=mon.getMonKey().getDetails(); data[1]=event.getLoggerName(); data[2]=event.getLevel().toString(); data[3]=event.getThreadName(); data[4]=(event.getThrowableInformation() == null || event.getThrowableInformation().getThrowable() == null) ? "" : Misc.getExceptionTrace(event.getThrowableInformation().getThrowable()); return data; }
row[SQL_EXCEPTION_IND]=Misc.getExceptionTrace(e);
stackTrace=Misc.getExceptionTrace(e); row[SQL_EXCEPTION_IND]=stackTrace;