/** * Indicates that application tracking event has ended. * * @param ccode * completion code of the tracking event * @param rcode * reason code associated with this tracking event * @param opEx * exception associated with this tracking event * @see OpCompCode */ public void stop(OpCompCode ccode, int rcode, Throwable opEx) { operation.setException(opEx); operation.setCompCode(ccode); operation.setReasonCode(rcode); operation.stop(); }
/** * Creates a Operation with the specified properties. Operation name can be any name or a relative name based on the * current thread stack trace. The relative operation name must be specified as follows: * {@code $class-marker:offset}. Example: {@code $com.jkoolcloud.tnt4j.tracker:0} This name results in the actual * operation name computed at runtime based on current thread stack at the time when {@link #getResolvedName()} is * called. * * @param opname * function name triggering operation * @param opType * operation type * @param threadTiming * enable/disable cpu, wait, block timing between start/stop * @see #getResolvedName() */ public Operation(String opname, OpType opType, boolean threadTiming) { setName(opname); setType(opType); setPID(Utils.getVMPID()); setTID(Thread.currentThread().getId()); enableTiming = threadTiming; }
/** * Indicates that application tracking event has ended. Event completion code is set to {@link OpCompCode#WARNING} * * @param opEx * exception associated with this tracking event */ public void stop(Throwable opEx) { operation.setException(opEx); operation.stop(); operation.setCompCode(opEx != null ? OpCompCode.WARNING : OpCompCode.SUCCESS); }
curEvent.getOperation().setPID(curActivity.getPID()); curEvent.getOperation().setTID(curActivity.getTID()); curEvent.getOperation().setResource(curActivity.getResource()); curEvent.getOperation().setUser(curActivity.getUser()); curEvent.getOperation().setSeverity(severity == null ? OpLevel.INFO : severity); curEvent.getOperation().setCompCode(cc == null ? OpCompCode.SUCCESS : cc); if (srcId > 0) { curEvent.setSource(source); curEvent.getOperation().setUser(user); } else if (curActivity == null) { curEvent.getOperation().setUser(source.getUser()); curEvent.getOperation().setPID(pid); curEvent.getOperation().setTID(tid); curEvent.getOperation().setName(name); curEvent.getOperation().setResource(res); curEvent.getOperation().setReasonCode(rc); curEvent.getOperation().setException(exc);
event.getOperation().setSeverity(level); event.setTag(jev.getThreadName()); event.getOperation().setResource(frame.getClassName()); event.setLocation(frame.getFileName() + ":" + frame.getLineNumber()); event.setSource(logger.getConfiguration().getSourceFactory().newSource(jev.getLoggerName())); event.setLocation(value); } else if (key.equalsIgnoreCase(PARAM_RESOURCE_LABEL)) { event.getOperation().setResource(value); } else if (key.equalsIgnoreCase(PARAM_USER_LABEL)) { event.getOperation().setUser(value); } else if (key.equalsIgnoreCase(PARAM_ELAPSED_TIME_LABEL)) { elapsedTimeUsec = Long.parseLong(value); ccode = OpCompCode.valueOf(value); } else if (key.equalsIgnoreCase(PARAM_SEVERITY_LABEL)) { event.getOperation().setSeverity(OpLevel.valueOf(value)); } else if (key.equalsIgnoreCase(PARAM_OP_TYPE_LABEL)) { event.getOperation().setType(OpType.valueOf(value)); } else if (key.equalsIgnoreCase(PARAM_OP_NAME_LABEL)) { event.getOperation().setName(value); } else if (key.equalsIgnoreCase(PARAM_EXCEPTION_LABEL)) { event.getOperation().setException(value); } else if (key.equalsIgnoreCase(PARAM_MSG_DATA_LABEL)) { event.setMessage(value); snapshot = logger.newSnapshot(SNAPSHOT_CATEGORY, event.getOperation().getName()); event.getOperation().addSnapshot(snapshot);
tevent.setLocation(value); } else if (key.equals(AppenderConstants.PARAM_RESOURCE_LABEL)) { tevent.getOperation().setResource(value); } else if (key.equals(AppenderConstants.PARAM_USER_LABEL)) { tevent.getOperation().setUser(value); } else if (key.equals(AppenderConstants.PARAM_OP_TYPE_LABEL)) { tevent.getOperation().setType(OpType.valueOf(value)); } else if (key.equals(AppenderConstants.PARAM_OP_NAME_LABEL)) { tevent.getOperation().setName(value); } else if (key.equals(AppenderConstants.PARAM_EXCEPTION_LABEL)) { tevent.getOperation().setException(value);
super(null, msg, args); tracker = tr; operation = new Operation(opName, opType); operation.setSeverity(severity); operation.setCorrelator(correlators); operation.setException(Utils.getThrowable(args)); setSource(src); setLocation(src);
/** * Process syslog message based on RFC5424 * * @param facility * syslog facility name * @param event * syslog message * @param tevent * tracking event * * @return tracking event */ protected TrackingEvent processRFC3164(String facility, SyslogServerEventIF event, TrackingEvent tevent) { Map<String, Object> map = parseAttributes(event); String appName = map.get("appl.name").toString(); String serverName = map.get("server.name").toString(); Long pid = (Long) map.get("appl.pid"); tevent.setTag(facility, serverName, appName); tevent.getOperation().setPID(pid); tevent.getOperation().setTID(pid); tevent.getOperation().setResource(appName); tevent.getOperation().setName(facility); // set the appropriate source SourceFactory factory = logger.getConfiguration().getSourceFactory(); Source rootSource = factory.getRootSource().getSource(SourceType.DATACENTER); tevent.setSource(factory.newSource(appName, SourceType.APPL, factory.newSource(serverName, SourceType.SERVER, rootSource))); return tevent; }
@Override public TrackingEvent newEvent(OpLevel severity, String opName, String correlator, String msg, Object... args) { long start = System.nanoTime(); try { if (!isTrackingEnabled(severity, opName, correlator, msg, args)) { return NULL_EVENT; } TrackingEvent event = new TrackingEvent(this, getSource(), severity, opName, correlator, msg, args); event.getOperation().setUser(tConfig.getSource().getUser()); return event; } finally { countOverheadNanos(System.nanoTime() - start); } }
@Override public void event(Object arg0, SyslogServerIF config, SocketAddress arg2, SyslogServerEventIF event) { Date date = (event.getDate() == null ? new Date() : event.getDate()); String facility = getFacilityString(event.getFacility()); OpLevel level = getOpLevel(event.getLevel()); TrackingEvent tevent = logger.newEvent(facility, event.getMessage()); tevent.getOperation().setSeverity(level); tevent.getOperation().addProperty(new Property("facility", facility)); tevent.getOperation().addProperty(new Property("hostname", event.getHost())); tevent.getOperation().addProperty(new Property("level", event.getLevel(), ValueTypes.VALUE_TYPE_ID)); if (arg2 instanceof InetSocketAddress) { InetSocketAddress from = (InetSocketAddress) arg2; tevent.getOperation().addProperty(new Property("hostaddr", from.getAddress().getHostAddress())); tevent.setLocation(from.getAddress().getHostAddress()); } else { tevent.setLocation(event.getHost()); } tevent.setCharset(config.getConfig().getCharSet()); if (event instanceof StructuredSyslogServerEvent) { processRFC5424(facility, (StructuredSyslogServerEvent) event, tevent); } else { processRFC3164(facility, event, tevent); } // extract name=value pairs if available extractVariables(event, tevent); String locationKey = tevent.getLocation() + "/" + tevent.getOperation().getResource(); tevent.stop(date.getTime() * 1000, getUsecSinceLastEvent(locationKey)); logger.tnt(tevent); }
/** * Extract and assign process id * * @param sevent * syslog structured message * @param tevent * tracking event */ protected void assignPid(StructuredSyslogServerEvent sevent, TrackingEvent tevent) { tevent.getOperation().setPID(0); String pid = sevent.getProcessId(); if (pid != null && !pid.isEmpty()) { try { tevent.getOperation().setPID(Long.parseLong(sevent.getProcessId())); } catch (NumberFormatException e) { } } tevent.getOperation().setTID(tevent.getOperation().getPID()); }
Utils.quote(event.getOperation().getType(), jsonString).append(ATTR_JSON); if (!Utils.isEmpty(event.getOperation().getResolvedName())) { String escaped = StringEscapeUtils.escapeJson(event.getOperation().getResolvedName()); // escape double event.getOperation().addSnapshot(selfSnapshot); int snapCount = event.getOperation().getSnapshotCount(); int propCount = event.getOperation().getPropertyCount();
/** * Process syslog message based on RFC5424 * * @param facility * syslog facility name * @param sevent * syslog structured message * @param tevent * tracking event * * @return tracking event */ protected TrackingEvent processRFC5424(String facility, StructuredSyslogServerEvent sevent, TrackingEvent tevent) { // RFC 5424 tevent.getOperation().setName(facility); tevent.getOperation().setResource(sevent.getApplicationName()); tevent.setTag(facility, sevent.getHost(), sevent.getApplicationName(), sevent.getStructuredMessage().getMessageId()); assignPid(sevent, tevent); // set the appropriate source SourceFactory factory = logger.getConfiguration().getSourceFactory(); Source rootSource = factory.getRootSource().getSource(SourceType.DATACENTER); tevent.setSource(factory.newSource(sevent.getApplicationName(), SourceType.APPL, factory.newSource(sevent.getHost(), SourceType.SERVER, rootSource))); // process structured event attributes into snapshot extractStructuredData(sevent, tevent); return tevent; }
/** * Extract syslog name/value pairs if available in within the message * * @param event * syslog event message * @param tevent * tracking event * @return map of parsed out event attributes (name=value pairs) */ protected Map<String, Object> extractVariables(SyslogServerEventIF event, TrackingEvent tevent) { Map<String, Object> attr = parseVariables(event.getMessage()); if (attr != null && attr.size() > 0) { extractSpecialKeys(attr, tevent); PropertySnapshot snap = new PropertySnapshot(SNAPSHOT_CAT_SYSLOG_VARS, tevent.getOperation().getResource(), tevent.getSeverity()); snap.addAll(attr); tevent.getOperation().addSnapshot(snap); } return attr; }
/** * {@inheritDoc} */ @Override public void endElement(String uri, String localName, String name) throws SAXException { if (name.equals(SIM_XML_MSG)) { recordMsgData(); curMsg = null; } else if (name.equals(SIM_XML_SNAPSHOT)) { if (curEvent != null) { curEvent.getOperation().addSnapshot(curSnapshot); } else { curActivity.add(curSnapshot); } curSnapshot = null; } else if (name.equals(SIM_XML_ACTIVITY)) { stopActivity(); } else if (name.equals(SIM_XML_EVENT)) { if (curActivity != null) { curActivity.tnt(curEvent); } else { Tracker tracker = trackers.get(curEvent.getSource().getFQName()); if (tracker != null) { tracker.tnt(curEvent); } } curEvent = null; } curElement = activeElements.pop(); }
/** * <p> * Sets the exception message to associate with the operation based on the specified exception. * </p> * * <p> * If an exception is associated with the operation, then the completion code should be set to either * {@code WARNING} or {@code ERROR}. * </p> * * @param t * error thrown by operation * @see #setCompCode(OpCompCode) */ public void setException(Throwable t) { exHandle = t; setException(Utils.printThrowable(exHandle)); }
curSnapshot.add(prop); } else if (SIM_XML_EVENT.equals(curElement)) { curEvent.getOperation().addProperty(prop); } else if (SIM_XML_ACTIVITY.equals(curElement)) { curActivity.addProperty(prop);
super(null, msg, args); tracker = tr; operation = new Operation(opName, opType); operation.setSeverity(severity); operation.setCorrelator(correlator); operation.setException(Utils.getThrowable(args)); setSource(src); setLocation(src);
/** * Indicates that application tracking event has ended. * * @param ccode * completion code of the tracking event * @param opEx * exception associated with this tracking event * @see OpCompCode */ public void stop(OpCompCode ccode, Throwable opEx) { operation.stop(); operation.setException(opEx); operation.setCompCode(ccode); }
@Override public TrackingEvent newEvent(String opName, String msg, Object... args) { long start = System.nanoTime(); try { if (!isTrackingEnabled(OpLevel.NONE, opName, msg, args)) { return NULL_EVENT; } TrackingEvent event = new TrackingEvent(this, getSource(), OpLevel.NONE, opName, (String) null, msg, args); event.getOperation().setUser(tConfig.getSource().getUser()); return event; } finally { countOverheadNanos(System.nanoTime() - start); } }