监控action访问时间

1:添加拦截器

import org.apache.commons.lang.time.StopWatch;

 

import com.njhh.fmcp.log.PortalRunLog;

import com.njhh.fmcp.util.BeanMaker;

import com.njhh.fmcp.util.SystemConfigUtil;

import com.opensymphony.xwork2.ActionInvocation;

import com.opensymphony.xwork2.interceptor.Interceptor;

 

/**

 * action 拦截器

 * @author

 *

 */

publicclass ActionInterceptorimplements Interceptor{

    /**

     *

     */

    privatestaticfinallongserialVersionUID = 1L;

    private PortalRunLoglog = (PortalRunLog)BeanMaker.getBean("monitorLog");

   

    @Override

    public String intercept(ActionInvocation invocation)throws Exception {

        //监控的类名

        String className =invocation.getAction().getClass().getSimpleName();

        //监控的方法名 

        String methodName = className +"." +invocation.getProxy().getMethod();

        StopWatch watch = new StopWatch();

        watch.start();

        String result = invocation.invoke();

        watch.stop();

        if (watch.getTime() > SystemConfigUtil.getPageTimeThresholdKey()){

            log.info("action执行时间:" + watch.getTime() + " ms [" + methodName +"]");

        }

        //System.out.println("action执行时间:" + watch.getTime() + " ms[" + methodName + "]");

        return result;

    }

 

    @Override

    publicvoid destroy() {

    }

 

    @Override

    publicvoid init() {

    }

   

}

2:修改strust.xml

<!-- 默认的配置包 -->

    <packagename="defaultPackage"extends="struts-default,json-default,jfreechart-default,spring-default">

        <!--配置拦截器 -->

        <interceptors>

            <interceptorname="actionInterceptor"class="com.njhh.fmcp.interceptor.ActionInterceptor"></interceptor>

             <!--自定义拦截链 -->

            <interceptor-stackname="actionStack">

                 <!--执行顺序与配置顺序有关 -->

                <interceptor-refname="actionInterceptor"></interceptor-ref>

                <interceptor-refname="defaultStack"></interceptor-ref>

            </interceptor-stack>

        </interceptors>

       

        <!--设置默认拦截链,一个package下只能配置一个,应用所有的没有配置拦截器或拦截链的Action -->

        <default-interceptor-ref name="actionStack"></default-interceptor-ref>

 

        <global-results>

            <!--公用返回页面 -->

            <resultname="success">/jsp/noticeMessage/success.jsp</result>

            <resultname="error">/jsp/noticeMessage/error.jsp</result>

            <resultname="login"type="dispatcher">/login.jsp</result>

            <resultname="defaultLogin"type="redirect">/quitSys.jsp</result>

            <resultname="loginOut"type="redirect">/loginAction!loginPage.action

            </result>

            <resultname="ajaxJson"type="json">

                <paramname="contentType">text/html</param>

                <paramname="root">ajax_json</param>

            </result>

            <!--异常返回页面 -->

            <resultname="actionException"type="dispatcher">/jsp/comm/error.jsp

            </result>

            <resultname="serviceException"type="dispatcher">/jsp/comm/error.jsp

            </result>

            <resultname="daoException"type="dispatcher">/jsp/comm/error.jsp

            </result>

            <resultname="exception"type="dispatcher">/jsp/comm/error.jsp

            </result>

        </global-results>

        <!--异常处理 -->

        <global-exception-mappings>

            <!-- Action层异常处理 -->

            <exception-mappingresult="actionException"

                exception="system.exception.ActionException"/>

            <!-- Service层异常处理 -->

            <exception-mappingresult="serviceException"

                exception="system.exception.ServiceException"/>

            <!-- DAO层异常处理 -->

            <exception-mappingresult="daoException"

                exception="system.exception.DaoException"/>

            <!--未知的系统异常,后台没有对此信息进行归类 -->

            <exception-mappingresult="exception"exception="java.lang.Exception"/>

        </global-exception-mappings>

    </package>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值