private String getAttributeAsStringWithDefault(Monitor monitor, String attributeKey, String defaultValue) { if (!monitor.hasAttribute(attributeKey)) { return defaultValue; } else { return monitor.getAsString(attributeKey); } }
@Override public void monitorStarted(final Monitor monitor) { if (isEnabled && TransactionMonitor.class.isAssignableFrom(monitor.getClass())) { String name = monitor.getAsString(Attribute.NAME); synchronized (map) { Integer cnt = map.get(name); if (cnt == null) { map.put(name, Integer.valueOf(1)); } else { int count = cnt.intValue(); map.put(name, Integer.valueOf(count + 1)); } } } }
protected boolean shouldRender(Monitor monitor) { boolean render = true; if(!logger.isDebugEnabled()) { if (monitor.hasAttribute(Attribute.NAME)) { String name = monitor.getAsString(Attribute.NAME); Iterator it = monitorsToSkip.iterator(); while(render && it.hasNext()) { String sName = (String) it.next(); if (name.indexOf(sName) > -1) { render = false; } } } } return render; }
/** * Given a monitor, look at its name and see if there has been an updated level set during * runtime. The updated level can apply for a specific monitor "com.orbitz.foo.bar" or any package * "com.orbitz.foo" * * @param monitor the monitor to check for an updated level * @return the appropiate level for this monitor, if a new level has been set at runtime that will * be returned, if not the monitor's level set at construction time will be returned. */ public MonitoringLevel getOverrideLevelForMonitor(final Monitor monitor) { final String name = monitor.getAsString(Attribute.NAME); final Set keys = monitorLevels.keySet(); final Iterator itr = keys.iterator(); String keyToUse = null; while (itr.hasNext()) { final String key = (String)itr.next(); if (name.startsWith(key)) { keyToUse = key; break; } } return (keyToUse != null ? (MonitoringLevel)monitorLevels.get(keyToUse) : null); }
@Override public void process(final Monitor monitor) { if (isEnabled && TransactionMonitor.class.isAssignableFrom(monitor.getClass())) { String name = monitor.getAsString(Attribute.NAME); synchronized (map) { Integer cnt = map.get(name); if (cnt == null) { log.warn("No count available for Monitor named " + name); } else { int count = cnt.intValue(); map.put(name, Integer.valueOf(count - 1)); monitor.set("concurrencyCount", count); } } } }
public void process(Monitor monitor) { if (monitor == null) { return; } if (monitor.hasAttribute(Attribute.LATENCY)) { _statsdClient.timing(monitor.getAsString(Attribute.NAME), monitor.getAsInt(Attribute.LATENCY)); } else if (monitor.hasAttribute(Attribute.VALUE)) { _statsdClient.gauge(monitor.getAsString(Attribute.NAME), (int) monitor.getAsInt(Attribute.VALUE)); } else { _statsdClient.increment(monitor.getAsString(Attribute.NAME)); } if (monitor.getAsBoolean(Attribute.FAILED, false)) { _statsdClient.increment(monitor.getAsString(Attribute.NAME) + ".failed"); } }
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); } } } } }