Search in sources :

Example 1 with IReceiverStatistics

use of nl.nn.adapterframework.core.IReceiverStatistics in project iaf by ibissource.

the class ShowAdapterStatistics method getStatistics.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/statistics")
@Relation("statistics")
@Produces(MediaType.APPLICATION_JSON)
public Response getStatistics(@PathParam("adapterName") String adapterName) throws ApiException {
    initBase(servletConfig);
    Map<String, Object> statisticsMap = new HashMap<String, Object>();
    Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    StatisticsKeeper sk = adapter.getStatsMessageProcessingDuration();
    statisticsMap.put("totalMessageProccessingTime", statisticsKeeperToMapBuilder(sk));
    long[] numOfMessagesStartProcessingByHour = adapter.getNumOfMessagesStartProcessingByHour();
    List<Map<String, Object>> hourslyStatistics = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < numOfMessagesStartProcessingByHour.length; i++) {
        Map<String, Object> item = new HashMap<String, Object>(2);
        String startTime;
        if (i < 10) {
            startTime = "0" + i + ":00";
        } else {
            startTime = i + ":00";
        }
        item.put("time", startTime);
        item.put("count", numOfMessagesStartProcessingByHour[i]);
        hourslyStatistics.add(item);
    }
    statisticsMap.put("hourly", hourslyStatistics);
    List<Map<String, Object>> receivers = new ArrayList<Map<String, Object>>();
    Iterator<?> recIt = adapter.getReceiverIterator();
    if (recIt.hasNext()) {
        while (recIt.hasNext()) {
            IReceiver receiver = (IReceiver) recIt.next();
            Map<String, Object> receiverMap = new HashMap<String, Object>();
            receiverMap.put("name", receiver.getName());
            receiverMap.put("class", receiver.getClass().getName());
            receiverMap.put("messagesReceived", receiver.getMessagesReceived());
            receiverMap.put("messagesRetried", receiver.getMessagesRetried());
            if (receiver instanceof IReceiverStatistics) {
                IReceiverStatistics statReceiver = (IReceiverStatistics) receiver;
                Iterator<?> statsIter;
                statsIter = statReceiver.getProcessStatisticsIterator();
                if (statsIter != null) {
                    ArrayList<Map<String, Object>> procStatsMap = new ArrayList<Map<String, Object>>();
                    // procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(statReceiver.getResponseSizeStatistics(), "stat"));
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        procStatsMap.add(statisticsKeeperToMapBuilder(pstat));
                    }
                    receiverMap.put("processing", procStatsMap);
                }
                statsIter = statReceiver.getIdleStatisticsIterator();
                if (statsIter != null) {
                    ArrayList<Map<String, Object>> idleStatsMap = new ArrayList<Map<String, Object>>();
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        idleStatsMap.add(statisticsKeeperToMapBuilder(pstat));
                    }
                    receiverMap.put("idle", idleStatsMap);
                }
                receivers.add(receiverMap);
            }
        }
    }
    statisticsMap.put("receivers", receivers);
    Map<String, Object> tmp = new HashMap<String, Object>();
    StatisticsKeeperToXml handler = new StatisticsKeeperToXml(tmp);
    handler.configure();
    Object handle = handler.start(null, null, null);
    try {
        adapter.getPipeLine().iterateOverStatistics(handler, tmp, HasStatistics.STATISTICS_ACTION_FULL);
        statisticsMap.put("durationPerPipe", tmp.get("pipeStats"));
        statisticsMap.put("sizePerPipe", tmp.get("sizeStats"));
    } catch (SenderException e) {
        log.error(e);
    } finally {
        handler.end(handle);
    }
    return Response.status(Response.Status.CREATED).entity(statisticsMap).build();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IReceiver(nl.nn.adapterframework.core.IReceiver) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IReceiverStatistics(nl.nn.adapterframework.core.IReceiverStatistics) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with IReceiverStatistics

use of nl.nn.adapterframework.core.IReceiverStatistics in project iaf by ibissource.

the class ShowAdapterStatistics method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    String adapterName = request.getParameter("adapterName");
    String deepString = request.getParameter("deep");
    boolean deep = "true".equals(deepString);
    Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
    XmlBuilder adapterXML = new XmlBuilder("adapterStatistics");
    adapterXML.addAttribute("name", adapter.getName());
    adapterXML.addAttribute("state", adapter.getRunState().toString());
    adapterXML.addAttribute("upSince", adapter.getStatsUpSince());
    adapterXML.addAttribute("lastMessageDate", adapter.getLastMessageDate());
    adapterXML.addAttribute("messagesInProcess", "" + adapter.getNumOfMessagesInProcess());
    adapterXML.addAttribute("messagesProcessed", "" + adapter.getNumOfMessagesProcessed());
    adapterXML.addAttribute("messagesInError", "" + adapter.getNumOfMessagesInError());
    StatisticsKeeper st = adapter.getStatsMessageProcessingDuration();
    adapterXML.addSubElement(statisticsKeeperToXmlBuilder(st, "messageProcessingDuration", deep));
    XmlBuilder messagesReceivedByHour = new XmlBuilder("messagesStartProcessingByHour");
    adapterXML.addSubElement(messagesReceivedByHour);
    long[] numOfMessagesStartProcessingByHour = adapter.getNumOfMessagesStartProcessingByHour();
    for (int i = 0; i < numOfMessagesStartProcessingByHour.length; i++) {
        XmlBuilder item = new XmlBuilder("item");
        messagesReceivedByHour.addSubElement(item);
        String startTime;
        if (i < 10) {
            startTime = "0" + i + ":00";
        } else {
            startTime = i + ":00";
        }
        item.addAttribute("startTime", startTime);
        item.addAttribute("count", numOfMessagesStartProcessingByHour[i]);
    }
    Iterator recIt = adapter.getReceiverIterator();
    if (recIt.hasNext()) {
        XmlBuilder receiversXML = new XmlBuilder("receivers");
        while (recIt.hasNext()) {
            IReceiver receiver = (IReceiver) recIt.next();
            XmlBuilder receiverXML = new XmlBuilder("receiver");
            receiversXML.addSubElement(receiverXML);
            receiverXML.addAttribute("name", receiver.getName());
            receiverXML.addAttribute("class", receiver.getClass().getName());
            receiverXML.addAttribute("messagesReceived", "" + receiver.getMessagesReceived());
            receiverXML.addAttribute("messagesRetried", "" + receiver.getMessagesRetried());
            /*				  
			    if (receiver instanceof HasSender) {
					ISender sender = ((HasSender) receiver).getSender();
				          if (sender != null) 
					          	receiverXML.addAttribute("senderName", sender.getName());
	 	        }
	*/
            if (receiver instanceof IReceiverStatistics) {
                IReceiverStatistics statReceiver = (IReceiverStatistics) receiver;
                Iterator statsIter;
                statsIter = statReceiver.getProcessStatisticsIterator();
                if (statsIter != null) {
                    XmlBuilder procStatsXML = new XmlBuilder("procStats");
                    // procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(statReceiver.getResponseSizeStatistics(), "stat"));
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(pstat, "stat", deep));
                    }
                    receiverXML.addSubElement(procStatsXML);
                }
                statsIter = statReceiver.getIdleStatisticsIterator();
                if (statsIter != null) {
                    XmlBuilder procStatsXML = new XmlBuilder("idleStats");
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(pstat, "stat", deep));
                    }
                    receiverXML.addSubElement(procStatsXML);
                }
            }
        }
        adapterXML.addSubElement(receiversXML);
    }
    StatisticsKeeperToXml handler = new StatisticsKeeperToXml(adapterXML, deep);
    handler.configure();
    Object handle = handler.start(null, null, null);
    try {
        Object pipelineData = handler.openGroup(handle, null, "pipeline");
        adapter.getPipeLine().iterateOverStatistics(handler, pipelineData, HasStatistics.STATISTICS_ACTION_FULL);
    } catch (SenderException e) {
        log.error(e);
    } finally {
        handler.end(handle);
    }
    if (log.isDebugEnabled()) {
        log.debug("about to set adapterStatistics [" + adapterXML.toXML() + "]");
    // XmlBuilder alt = new XmlBuilder("alt");
    // StatisticsKeeperToXml hh = new StatisticsKeeperToXml(alt);
    // adapter.forEachStatisticsKeeper(hh,HasStatistics.STATISTICS_ACTION_NONE);
    // log.debug("alternative ["+alt.toXML()+"]");
    }
    request.setAttribute("adapterStatistics", adapterXML.toXML());
    // Forward control to the specified success URI
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : Adapter(nl.nn.adapterframework.core.Adapter) IReceiver(nl.nn.adapterframework.core.IReceiver) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IReceiverStatistics(nl.nn.adapterframework.core.IReceiverStatistics) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

Adapter (nl.nn.adapterframework.core.Adapter)2 IReceiver (nl.nn.adapterframework.core.IReceiver)2 IReceiverStatistics (nl.nn.adapterframework.core.IReceiverStatistics)2 SenderException (nl.nn.adapterframework.core.SenderException)2 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1