Search in sources :

Example 1 with CaptureContext

use of com.creditease.monitor.captureframework.spi.CaptureContext in project uavstack by uavorg.

the class AppCustomMonitor method doGet.

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest request,
 *      javax.servlet.http.HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    /**
     * get your defined application monitor
     */
    Monitor monitor = MonitorFactory.instance().getMonitor("AppCustomMonitor");
    /**
     * create CaptureContext to wrap anything wish to pass MyAppMonitorCounterHandler
     */
    CaptureContext context = monitor.getCaptureContext();
    context.put(HttpServletRequest.class, request);
    context.put(HttpServletResponse.class, response);
    /**
     * do DOCAP operation, then MyAppMonitorCounterHandler is notified to do the same operation
     */
    monitor.doCapture("AppCustomMonitor.doGet", context, CapturePhase.DOCAP);
    request.getSession().setAttribute("test", 1);
}
Also used : CaptureContext(com.creditease.monitor.captureframework.spi.CaptureContext) Monitor(com.creditease.monitor.captureframework.spi.Monitor)

Example 2 with CaptureContext

use of com.creditease.monitor.captureframework.spi.CaptureContext in project uavstack by uavorg.

the class MonitorObserver method getData.

@Override
public String getData() {
    // run state related capture
    CaptureContext context = monitor.getCaptureContext();
    monitor.doCapture(CaptureConstants.CAPPOINT_MONITOR_DATAOBSERVER, context, CapturePhase.DOCAP);
    // run preStore
    monitor.doPreStore();
    // gen JSON data
    data = monitor.getRepository().toJSONString();
    // in case of \\ to /
    data = data.replace("\\", "/");
    return data;
}
Also used : CaptureContext(com.creditease.monitor.captureframework.spi.CaptureContext)

Example 3 with CaptureContext

use of com.creditease.monitor.captureframework.spi.CaptureContext in project uavstack by uavorg.

the class StandardCaptureContextHelper method get.

private CaptureContext get(String monitorId) {
    if (monitorId == null)
        return null;
    CaptureContext context = threadMonitorCaptureContexts.get(monitorId);
    if (context == null) {
        context = new StandardCaptureContext();
        threadMonitorCaptureContexts.put(monitorId, context);
    }
    return context;
}
Also used : CaptureContext(com.creditease.monitor.captureframework.spi.CaptureContext)

Example 4 with CaptureContext

use of com.creditease.monitor.captureframework.spi.CaptureContext in project uavstack by uavorg.

the class UAVServer method runMonitorAsyncCaptureOnServerCapPoint.

/**
 * runMonitorAsyncCaptureOnServerCapPoint
 *
 * @param captureId
 * @param phase
 * @param contextParams
 * @param CaptureContextMapFromAnotherThread
 * @return
 */
public Map<String, CaptureContext> runMonitorAsyncCaptureOnServerCapPoint(String captureId, CapturePhase phase, Map<String, Object> contextParams, Map<String, CaptureContext> CaptureContextMapFromAnotherThread) {
    long st = System.currentTimeMillis();
    Map<String, CaptureContext> curCaptureContextMap = new HashMap<String, CaptureContext>();
    Monitor[] monitors = MonitorFactory.instance().getServerCapPointBindMonitors(captureId, phase);
    if (monitors == null || monitors.length == 0) {
        return curCaptureContextMap;
    }
    for (Monitor monitor : monitors) {
        CaptureContext context = monitor.getCaptureContext();
        /**
         * if CaptureContextMapFromAnotherThread exists, need merge CaptureContext first
         */
        if (CaptureContextMapFromAnotherThread != null) {
            CaptureContext anotherCC = CaptureContextMapFromAnotherThread.get(monitor.getId());
            if (anotherCC != null) {
                context.put(anotherCC.getAll());
            }
        }
        if (contextParams != null) {
            context.put(contextParams);
        }
        // tmp store CaptureContext
        curCaptureContextMap.put(monitor.getId(), context);
        monitor.doCapture(captureId, context, phase);
        // release capture context when PRECAP or DOCAP is done
        monitor.releaseCaptureContext();
    }
    if (this.monitor != null) {
        this.monitor.logPerf(st, "");
    }
    return curCaptureContextMap;
}
Also used : CaptureContext(com.creditease.monitor.captureframework.spi.CaptureContext) Monitor(com.creditease.monitor.captureframework.spi.Monitor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 5 with CaptureContext

use of com.creditease.monitor.captureframework.spi.CaptureContext in project uavstack by uavorg.

the class UAVServer method runMonitorCaptureOnServerCapPoint.

/**
 * runMonitorCaptureOnServerCapPoint
 *
 * @param captureId
 * @param phase
 * @param contextParams
 */
public void runMonitorCaptureOnServerCapPoint(String captureId, CapturePhase phase, Map<String, Object> contextParams) {
    long st = System.currentTimeMillis();
    Monitor[] monitors = MonitorFactory.instance().getServerCapPointBindMonitors(captureId, phase);
    if (monitors == null || monitors.length == 0) {
        return;
    }
    String contextTag = null;
    if (contextParams != null) {
        contextTag = (String) contextParams.get(CaptureConstants.INFO_CAPCONTEXT_TAG);
    }
    for (Monitor monitor : monitors) {
        CaptureContext context = null;
        if (null == contextTag) {
            context = monitor.getCaptureContext();
        } else {
            context = monitor.getCaptureContext(contextTag);
        }
        if (contextParams != null) {
            context.put(contextParams);
        }
        monitor.doCapture(captureId, context, phase);
        // release capture context when DOCAP is done
        if (phase == CapturePhase.DOCAP) {
            if (null == contextTag) {
                monitor.releaseCaptureContext();
            } else {
                monitor.releaseCaptureContext(contextTag);
            }
        }
    }
    if (this.monitor != null) {
        this.monitor.logPerf(st, "");
    }
}
Also used : CaptureContext(com.creditease.monitor.captureframework.spi.CaptureContext) Monitor(com.creditease.monitor.captureframework.spi.Monitor)

Aggregations

CaptureContext (com.creditease.monitor.captureframework.spi.CaptureContext)5 Monitor (com.creditease.monitor.captureframework.spi.Monitor)3 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1