@SuppressWarnings("all") public static Monitor getStatisticMonitor( String label) { return MonitorFactory.getMonitor(label, "double"); } @SuppressWarnings("all")
@SuppressWarnings("all") public static Monitor getStatisticMonitor( String label, String unit) { return MonitorFactory.getMonitor(label, unit); }
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")); }
/** * Run the code in a new thread after a delay * * @param invocation * The code to run * @param millis * The time to wait before, in milliseconds * @return The future object, to know when the task is completed */ public static Future<?> invoke(Invocation invocation, long millis) { Monitor monitor = MonitorFactory.getMonitor("Invocation queue", "elmts."); monitor.add(executor.getQueue().size()); return executor.schedule(invocation, millis, TimeUnit.MILLISECONDS); }
/** If true is passed in then a buffer will contain the most recent stack traces. This is viewable via the jamon * web app or programmatically. This is very handy for debugging. * * By default this is enabled (true) * @param enable */ public void setExceptionBufferListener(boolean enable) { MonKey key = new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, EXCEPTION); boolean hasBufferListener = MonitorFactory.getMonitor(key).hasListener("value", "FIFOBuffer"); if (enable && !hasBufferListener) { MonitorFactory.getMonitor(key).addListener("value", JAMonListenerFactory.get("FIFOBuffer")); } else if (!enable && hasBufferListener) { MonitorFactory.getMonitor(key).removeListener("value", "FIFOBuffer"); } }
/** * Return hits/count of the passed in monitor if it exists otherwise return 0 * * @param label jamon label * @param units jamon units * @return count */ static long getCount(String label, String units) { if (MonitorFactory.exists(label, units)) { Monitor mon = MonitorFactory.getMonitor(label, units); return (long) mon.getHits(); } return 0; }
/** * * @param label jamon label * @param units jamon units * @param value string representing the date metric to return lastaccess, firstaccess. * @return The date associated with the jamon monitor */ static Date getDate(String label, String units, String value) { if (MonitorFactory.exists(label, units)) { Monitor mon = MonitorFactory.getMonitor(label, units); return (Date) mon.getValue(value); } return null; }
/** * Return the value of the passed in monitor if it exists otherwise return 0 * * @param label jamon label * @param units jamon units * @param value string representing the metric to return i.e. avg, hits etc. * @return the metric */ static double getDouble(String label, String units, String value) { if (MonitorFactory.exists(label, units)) { Monitor mon = MonitorFactory.getMonitor(label, units); return (Double) mon.getValue(value); } return 0.0; }
@Override public void addListeners(List<JamonPropertiesLoader.JamonListenerProperty> listeners) { Iterator<JamonPropertiesLoader.JamonListenerProperty> iter = listeners.iterator(); while (iter.hasNext()) { JamonPropertiesLoader.JamonListenerProperty listenerInfo = iter.next(); Monitor mon = MonitorFactory.getMonitor(listenerInfo.getLabel(), listenerInfo.getUnits()); mon.addListener(listenerInfo.getListenerType(), JAMonListenerFactory.get(listenerInfo.getListenerName())); } }
@SuppressWarnings("all") public static void increaseCount (Class clazz, String label) { // MonitorFactory.getMonitor(getMonitorPrefix(clazz)+label, "#").add(1.0); Monitor m = MonitorFactory.getMonitor(getMonitorPrefix(clazz)+label, "count"); // System.out.println(m); m.setHits(m.getHits()+1); //System.out.println(m); }
@Override public String getMostRecentException() { if (!MonitorFactory.exists(LABEL, UNITS)) { return "No exceptions have been thrown"; } if (!MonitorFactory.getMonitor(LABEL, UNITS).hasListener("value", "FIFOBuffer")) { return "Exception Stacktrace tracking is not enabled."; } JAMonListener listener = MonitorFactory.getMonitor(LABEL, UNITS).getListenerType("value").getListener("FIFOBuffer"); if (!(listener instanceof JAMonBufferListener) || ((JAMonBufferListener) listener).isEmpty()) { return "There are no stacktraces"; } return getMostRecentStacktrace((JAMonBufferListener) listener); }
/** * Run the code in a new thread took from a thread pool. * * @param invocation * The code to run * @return The future object, to know when the task is completed */ public static Future<?> invoke(Invocation invocation) { Monitor monitor = MonitorFactory.getMonitor("Invoker queue size", "elmts."); monitor.add(executor.getQueue().size()); invocation.waitInQueue = MonitorFactory.start("Waiting for execution"); return executor.submit(invocation); }
/** Pass in an array with col1=lables, and col2=units and then call methods */ public static MonitorComposite getMonitors(String[][] labels) { int numRows=(labels==null) ? 0 : labels.length; int numCols=(labels[0]==null) ? 0 : labels[0].length; Monitor[] monArray=new Monitor[numRows]; for (int i=0; i<numRows; i++) { MonKey key=null; if (numCols==2)// i.e 2 columns - summary, units (ex: sp_proc ?, ms.) key=new MonKeyImp(labels[i][0],labels[i][1]); else if (numCols==3) // 3 columns - summary, detail, units (ex: sp_proc ?, sp_proc 'steve', ms.) key=new MonKeyImp(labels[i][0],labels[i][1], labels[i][2]); monArray[i]=MonitorFactory.getMonitor(key); } return new MonitorComposite(monArray); }
/** Pass in an array with col1=lables, and col2=units and then call methods */ public static MonitorComposite getMonitors(String[][] labels) { int numRows=(labels==null) ? 0 : labels.length; int numCols=(labels[0]==null) ? 0 : labels[0].length; Monitor[] monArray=new Monitor[numRows]; for (int i=0; i<numRows; i++) { MonKey key=null; if (numCols==2)// i.e 2 columns - summary, units (ex: sp_proc ?, ms.) key=new MonKeyImp(labels[i][0],labels[i][1]); else if (numCols==3) // 3 columns - summary, detail, units (ex: sp_proc ?, sp_proc 'steve', ms.) key=new MonKeyImp(labels[i][0],labels[i][1], labels[i][2]); monArray[i]=MonitorFactory.getMonitor(key); } return new MonitorComposite(monArray); }
/** * Start the monitor. */ public void start() { if(this.isActive) { // when reseting using the JAMon GUI the custom ranges are discarded MonitorFactory.setRangeDefault(MONITOR_LABEL, Jamon2PerformanceMonitorImpl.rangeHolder); // do the internal house-keeping this.startTime = System.currentTimeMillis(); MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(this.method, 0); String methodSignature = methodToStringBuilder.toString(); this.monitor = MonitorFactory.getMonitor(methodSignature, MONITOR_LABEL); this.monitor.start(); } }
public void init(MonKeyImp oldMonkey) { Monitor[] marr = new Monitor[sizeOfResultVector]; for (int i = 0; i < sizeOfResultVector; i++) { MonKeyImp newMonKey = mon(oldMonkey, i); if (newMonKey.getUnits().equals(JamonMonitorLogger.MS)) { marr[i] = MonitorFactory.getTimeMonitor(newMonKey); } else { marr[i] = MonitorFactory.getMonitor(newMonKey); } } MonitorComposite m = new MonitorComposite(marr); mcs.add(m); put(oldMonkey, m); putRev(m, oldMonkey); }
private JAMonBufferListener getExceptionBufferListener() { if (MonitorFactory.exists(MonitorFactory.EXCEPTIONS_LABEL, EXCEPTION)) { Monitor mon = MonitorFactory.getMonitor(MonitorFactory.EXCEPTIONS_LABEL, EXCEPTION); if (mon.hasListener("value", "FIFOBuffer")) { JAMonListener bufferListener = mon.getListenerType("value").getListener("FIFOBuffer"); if (bufferListener instanceof JAMonBufferListener) { return (JAMonBufferListener) bufferListener; } } } return null; }
/** * Note. I am no longer sure that the following statements still hold true for jetty. 2/15/15 * * Jetty Handlers does not let jamon start/stop time them. It seems the request is done by the time jamon gets it. * To overcome this use the jetty api to get the time of a request for a page. If it isn't a jetty request then call * the parent. Note although start is called because the timing for jetty is done after the request is finished * 'active' statistics will not be accurate. */ @Override // Only called if this is a time monitor i.e units are 'ms.' Monitor startTimeMon(HttpMonRequest httpMonBase) { if (httpMonBase.getRequest() instanceof Request) return MonitorFactory.getMonitor(getMonKey(httpMonBase)).start(); else return super.startTimeMon(httpMonBase); }
/** * Return the first monitor that exists in the passed in list. * * @param jmxBeanProperties * @return The found monitor based on label, and units or null if none is found */ static Monitor getMonitor(List<JamonJmxBeanProperty> jmxBeanProperties) { for (JamonJmxBeanProperty jmxBeanProperty: jmxBeanProperties) { if (MonitorFactory.exists(jmxBeanProperty.getLabel(), jmxBeanProperty.getUnits())) { return MonitorFactory.getMonitor(jmxBeanProperty.getLabel(), jmxBeanProperty.getUnits()); } } return null; }