Search in sources :

Example 1 with RouteStatDump

use of org.apache.camel.util.RouteStatDump in project camel by apache.

the class RouteInfoCommand method executeOnRoute.

@Override
public void executeOnRoute(CamelController camelController, String contextName, String routeId, PrintStream out, PrintStream err) throws Exception {
    out.println(stringEscape.unescapeJava("Camel Route " + routeId + ""));
    out.println(stringEscape.unescapeJava("\tCamel Context: " + contextName));
    String xml = camelController.getRouteStatsAsXml(routeId, contextName, true, false);
    if (xml != null) {
        JAXBContext context = JAXBContext.newInstance(RouteStatDump.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        RouteStatDump route = (RouteStatDump) unmarshaller.unmarshal(new StringReader(xml));
        out.println(stringEscape.unescapeJava("\tState: " + route.getState()));
        out.println(stringEscape.unescapeJava("\tState: " + route.getState()));
        out.println("");
        out.println("");
        out.println(stringEscape.unescapeJava("Statistics"));
        long total = route.getExchangesCompleted() + route.getExchangesFailed();
        out.println(stringEscape.unescapeJava("\tExchanges Total: " + total));
        out.println(stringEscape.unescapeJava("\tExchanges Completed: " + route.getExchangesCompleted()));
        out.println(stringEscape.unescapeJava("\tExchanges Failed: " + route.getExchangesFailed()));
        out.println(stringEscape.unescapeJava("\tExchanges Inflight: " + route.getExchangesInflight()));
        out.println(stringEscape.unescapeJava("\tMin Processing Time: " + route.getMinProcessingTime() + " ms"));
        out.println(stringEscape.unescapeJava("\tMax Processing Time: " + route.getMaxProcessingTime() + " ms"));
        out.println(stringEscape.unescapeJava("\tMean Processing Time: " + route.getMeanProcessingTime() + " ms"));
        out.println(stringEscape.unescapeJava("\tTotal Processing Time: " + route.getTotalProcessingTime() + " ms"));
        out.println(stringEscape.unescapeJava("\tLast Processing Time: " + route.getLastProcessingTime() + " ms"));
        out.println(stringEscape.unescapeJava("\tDelta Processing Time: " + route.getDeltaProcessingTime() + " ms"));
        if (isEmpty(route.getStartTimestamp())) {
            // Print an empty value for scripting
            out.println(stringEscape.unescapeJava("\tStart Statistics Date:"));
        } else {
            Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getStartTimestamp());
            String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
            out.println(stringEscape.unescapeJava("\tStart Statistics Date: " + text));
        }
        // Test for null to see if a any exchanges have been processed first to avoid NPE
        if (isEmpty(route.getResetTimestamp())) {
            // Print an empty value for scripting
            out.println(stringEscape.unescapeJava("\tReset Statistics Date:"));
        } else {
            Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getResetTimestamp());
            String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
            out.println(stringEscape.unescapeJava("\tReset Statistics Date: " + text));
        }
        // Test for null to see if a any exchanges have been processed first to avoid NPE
        if (isEmpty(route.getFirstExchangeCompletedTimestamp())) {
            // Print an empty value for scripting
            out.println(stringEscape.unescapeJava("\tFirst Exchange Date:"));
        } else {
            Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getFirstExchangeCompletedTimestamp());
            String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
            out.println(stringEscape.unescapeJava("\tFirst Exchange Date: " + text));
        }
        // Test for null to see if a any exchanges have been processed first to avoid NPE
        if (isEmpty(route.getLastExchangeCompletedTimestamp())) {
            // Print an empty value for scripting
            out.println(stringEscape.unescapeJava("\tLast Exchange Date:"));
        } else {
            Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getLastExchangeCompletedTimestamp());
            String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
            out.println(stringEscape.unescapeJava("\tLast Exchange Date: " + text));
        }
    }
}
Also used : RouteStatDump(org.apache.camel.util.RouteStatDump) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with RouteStatDump

use of org.apache.camel.util.RouteStatDump in project camel by apache.

the class RouteProfileCommand method executeOnRoute.

@Override
public void executeOnRoute(CamelController camelController, String contextName, String routeId, PrintStream out, PrintStream err) throws Exception {
    JAXBContext context = JAXBContext.newInstance(RouteStatDump.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    // write new header for new camel context
    if (previousCamelContextName == null || !previousCamelContextName.equals(contextName)) {
        out.println("");
        out.println(stringEscape.unescapeJava("Profile"));
        out.println(stringEscape.unescapeJava("\tCamel Context: " + contextName));
        out.println(String.format(HEADER_FORMAT, "Id", "Count", "Last (ms)", "Delta (ms)", "Mean (ms)", "Min (ms)", "Max (ms)", "Total (ms)", "Self (ms)"));
    }
    String xml = camelController.getRouteStatsAsXml(routeId, contextName, true, true);
    if (xml != null) {
        RouteStatDump route = (RouteStatDump) unmarshaller.unmarshal(new StringReader(xml));
        long count = route.getExchangesCompleted() + route.getExchangesFailed();
        out.println(String.format(OUTPUT_FORMAT, route.getId(), count, route.getLastProcessingTime(), route.getDeltaProcessingTime(), route.getMeanProcessingTime(), route.getMinProcessingTime(), route.getMaxProcessingTime(), route.getTotalProcessingTime(), route.getSelfProcessingTime()));
        for (ProcessorStatDump ps : route.getProcessorStats()) {
            // the self time is the total time of the processor itself
            long selfTime = ps.getTotalProcessingTime();
            count = ps.getExchangesCompleted() + ps.getExchangesFailed();
            // indent route id with 2 spaces
            out.println(String.format(OUTPUT_FORMAT, "  " + ps.getId(), count, ps.getLastProcessingTime(), ps.getDeltaProcessingTime(), ps.getMeanProcessingTime(), ps.getMinProcessingTime(), ps.getMaxProcessingTime(), ps.getAccumulatedProcessingTime(), selfTime));
        }
    }
    // we want to group routes from the same context in the same table
    previousCamelContextName = contextName;
}
Also used : ProcessorStatDump(org.apache.camel.util.ProcessorStatDump) RouteStatDump(org.apache.camel.util.RouteStatDump) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

StringReader (java.io.StringReader)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 RouteStatDump (org.apache.camel.util.RouteStatDump)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ProcessorStatDump (org.apache.camel.util.ProcessorStatDump)1