/** * Accepts the given monitor if that current sample percentage is less than the target sample rate. * * @param monitor monitor instance * @return true if the monitor should be accepted in the sample */ public boolean accept(Monitor monitor) { sampleRateLock.lock(); boolean shouldAccept; float actualRate; try { if (populationCount == Integer.MAX_VALUE) { populationCount = 0; sampledCount = 0; } populationCount++; actualRate = (sampledCount / ((float)populationCount)); shouldAccept = (actualRate < sampleRate); if (shouldAccept) { sampledCount++; } } finally { sampleRateLock.unlock(); } if (logger.isDebugEnabled()) { logger.debug((shouldAccept ? "ACCEPTED" : "REJECTED") + " monitor \"" + monitor.get(Monitor.NAME) + "\" due to actual sample rate of " + actualRate + " and target " + this.sampleRate); } return shouldAccept; }
protected void appendMonitorDataAsAttributes(HierarchicalStreamWriter writer, Monitor monitor) { Iterator it = allowedAttributes.iterator(); while (it.hasNext()) { String attributeName = (String) it.next(); if (monitor.hasAttribute(attributeName)) { String attributeValue = monitor.getAsString(attributeName); if (attributeValue == null) { writer.addAttribute(attributeName, "null"); } else { if (attributeValue.indexOf("LazyDynaBean") > -1) { DynaBean dynaBean = (DynaBean) monitor.get(attributeName); Object clazz = dynaBean.get("class"); if (clazz != null) { attributeValue = clazz.toString(); } } int idx = attributeValue.indexOf("\n"); if(idx > -1) { attributeValue = attributeValue.substring(0, idx); } writer.addAttribute(attributeName, attributeValue); } } } } }
public int clearCurrentThread() { LinkedList stack = getStack(); int count = 0; if (stack != null) { count = stack.size(); if (count > 0) { StringBuffer monitorNames = new StringBuffer(); for (Iterator i = stack.iterator(); i.hasNext();) { StackFrame stackFrame = (StackFrame) i.next(); Monitor m = stackFrame.getCompositeMonitor(); String s = (String) m.get(Attribute.NAME); if (monitorNames.length() > 0) { monitorNames.append(", "); } monitorNames.append(s); } log.warn("clearing old CompositeMonitor refs for current thread; "+count+" found; names: "+monitorNames); stack.clear(); } } return count; }
public void process(Monitor monitor) { if (CompositeMonitor.class.isAssignableFrom(monitor.getClass()) && !monitor.hasAttribute("resultCode")) { if (monitor.hasAttribute("failureThrowable")) { Throwable t = (Throwable) monitor.get("failureThrowable"); while (t.getCause() != null) { t = t.getCause(); } monitor.set("resultCode", t.getClass().getName()); } else { monitor.set("resultCode", "success"); } } } }
return; Object o = monitor.get(Attribute.FAILURE_THROWABLE); if (Throwable.class.isAssignableFrom(o.getClass())) { Throwable t = (Throwable) o;
assignFailureThrowable(monitor, buffer); } else if (monitor.hasAttribute(attributeName)) { Object attributeValue = monitor.get(attributeName); buffer.append(attributeValue).append(delimeter);