Search in sources :

Example 1 with Monitor

use of com.creditease.monitor.captureframework.spi.Monitor 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 Monitor

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

the class AbsDBPoolHookProxy method run.

@Override
public void run(HookContext context) {
    String check = (String) context.get("monitor.client.prestore");
    if (check == null) {
        return;
    }
    /**
     * Step 1: 从ClientMonitor去clientResp的MonitorElem
     */
    Monitor monitor = MonitorFactory.instance().getMonitor(CaptureConstants.MONITOR_CLIENT);
    MonitorElement[] meElem = monitor.getRepository().getElementByMoElemIdAndCapId(CaptureConstants.MOELEM_CLIENT_RESPTIME, CaptureConstants.CAPPOINT_APP_CLIENT);
    MonitorElement clientElem = meElem[0];
    collectDBPoolMetrics(clientElem);
}
Also used : Monitor(com.creditease.monitor.captureframework.spi.Monitor) MonitorElement(com.creditease.monitor.captureframework.spi.MonitorElement)

Example 3 with Monitor

use of com.creditease.monitor.captureframework.spi.Monitor 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 4 with Monitor

use of com.creditease.monitor.captureframework.spi.Monitor 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

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