Order status and order amount database design and implementation of real-time monitoring (Java implementation)

Recently a need to do regular monitoring database synchronization results, one day to do a simple web monitoring system, what specific analysis for everyone.

First, the database design

 TABLE `table_monitor` the CREATE (
  ` id` BIGINT (20 is) the AUTO_INCREMENT the NOT NULL,
  `msql` VARCHAR (255) the DEFAULT NULL,
  ` mcompare` VARCHAR (50) the DEFAULT NULL,
  `mnum` decimal (10,2) the DEFAULT NULL,
  ` VARCHAR mdes` (50) the DEFAULT NULL,
  `type` int (20 is) the DEFAULT '. 1' the COMMENT '= SQL monitor. 1, 2 = monitoring URLs',
  a PRIMARY KEY (` id`)
) ENGINE = MyISAM the AUTO_INCREMENT = 54 is the DEFAULT the CHARSET = UTF8;
 
the CREATE TABLE table_monitor_result` `(
  ` id` BIGINT (20 is) the AUTO_INCREMENT the NOT NULL,
  `createTime` the COMMENT datetime the DEFAULT NULL 'processing time',
  ` mSQL` VARCHAR (255) the COMMENT the DEFAULT NULL 'monitoring SQL or address',
  `mResult `text DEFAULT NULL COMMENT 'monitoring results',
  ` doResult` VARCHAR (50) NULL the DEFAULT the COMMENT "processing result",
  `doMsg` text DEFAULT NULL COMMENT 'treatment Notes',
  a PRIMARY KEY (` id`)
) ENGINE = MyISAM the DEFAULT the CHARSET = UTF8;


Second, the monitoring data to achieve than

     //检测ERP数据库中的订单状态
    public void monitorOrderStatus() {
        long startTime=System.currentTimeMillis();
        try {
            String COM_EQUAL = "=";
            String COM_GREATER_THAN = ">";
            String COM_LESS_THAN = "<";
            List<PageData> list = this.query(Common.MONITOR_TYPE_ORDERSTATUS);
            int size = StringUtil.getListSize(list);
            for (int i = 0; i < size; i++) {
                //获取监控SQL
                PageData pd = list.get(i);
                String id = (String) pd.get("mid");
                String msql = pd.getString("msql");
                String mcompare = pd.getString("mcompare");
                = MNUM the BigDecimal (the BigDecimal) pd.get ( "MNUM");
                String MDEs for pd.getString = ( "MDEs for");
                MDEs for ID = + MDEs for;
                // check
                the PageData queryResultPD = this.executeERPSelectSQL (mSQL);
                Double Double dbnum = .parseDouble (queryResultPD.get ( "COUNT") + "");
                Double expectnum = mnum.doubleValue ();
                // send text messages in question
                if (COM_EQUAL.equals (mcompare) Math.abs ( dbnum - expectnum)>? 0.01: to false) {
                    this.monitorFailure (mSQL, MDEs for + "! database inaccurate data value" + dbnum + ", the expected value is" + expectnum);
                } the else IF (COM_GREATER_THAN.equals(mcompare) ? getScale(dbnum - expectnum) < 0.00 : false) {
                    this.monitorFailure (msql, mdes + "data library is not allowed!" + dbnum + ", the expected value is" + expectnum);
                } the else IF (COM_LESS_THAN.equals (mcompare) getScale (dbnum - expectnum)> 0.00?: to false) {
                    this.monitorFailure (mSQL, MDEs for + "database data is not allowed!" + dbnum + ", the expected value is" + expectnum);
                }
            }
        } the catch (Exception E) {
            this.monitorFailure ( "", Tools .getExceptionAllinformation (E), to false);
            this.sendMsg ( "order status data detection failure, failure reason" + e.getMessage ());
        }
        IF (Common.NOTE_MSG) {
            this.sendMsg ( "order status data detection completion, total time "+ (System.currentTimeMillis () - startTime ) +" msec ");
        }
    }

    //检测ERP数据库中的订单金额
    public void monitorOrderMoney() {
        long startTime=System.currentTimeMillis();
        try {
            String COM_EQUAL = "=";
            String COM_GREATER_THAN = ">";
            String COM_LESS_THAN = "<";
            List<PageData> list = this.query(Common.MONITOR_TYPE_ORDERMONEY);
            int size = StringUtil.getListSize(list);
            for (int i = 0; i < size; i++) {
                //获取监控SQL
                PageData pd = list.get(i);
                String id = (String) pd.get("mid");
                String msql = pd.getString("msql");
                String mcompare = pd.getString("mcompare");
                = MNUM the BigDecimal (the BigDecimal) pd.get ( "MNUM");
                String MDEs for pd.getString = ( "MDEs for");
                MDEs for ID = + MDEs for;
                // check
                the PageData queryResultPD = this.executeERPSelectSQL (mSQL);
                Double Double dbnum = .parseDouble (queryResultPD.get ( "COUNT") + "");
                Double expectnum = mnum.doubleValue ();
                // send text messages in question
                if (COM_EQUAL.equals (mcompare) Math.abs ( dbnum - expectnum)>? 0.01: to false) {
                    this.monitorFailure (mSQL, MDEs for + "! database inaccurate data value" + dbnum + ", the expected value is" + expectnum);
                } the else IF (COM_GREATER_THAN.equals(mcompare) ? getScale(dbnum - expectnum) < 0.00 : false) {
                    this.monitorFailure (msql, mdes + "data library is not allowed!" + dbnum + ", the expected value is" + expectnum);
                } the else IF (COM_LESS_THAN.equals (mcompare) getScale (dbnum - expectnum)> 0.00?: to false) {
                    this.monitorFailure (mSQL, MDEs for + "database data is not allowed!" + dbnum + ", the expected value is" + expectnum);
                }
            }
        } the catch (Exception E) {
            this.monitorFailure ( "", Tools .getExceptionAllinformation (E), to false);
            this.sendMsg ( "order amount data detection failure, failure cause" + e.getMessage ());
        }
    }


Third, to achieve regular monitoring

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"  
       xmlns:amq="http://activemq.apache.org/schema/core" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
         http://activemq.apache.org/schema/core 
         http://activemq.apache.org/schema/core/activemq-core.xsd">  
        <!-- 添加调度的任务bean 配置对应的class-->
        <bean id="tableQuartz" class="com.zrsc.table.common.TableQuartz"></bean>
       
        <bean id="monitorOrderStatusAndMoneyJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject" ref="tableQuartz"></property>
            <property name="targetMethod" value="monitorOrderStatusAndMoney"></property><!-- 配置调度指定类中的指定的方法 -->
            <property name="concurrent" value="false"></property>
        </bean>

 

        <bean id="monitorOrderStatusAndMoneyTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail" ref="monitorOrderStatusAndMoneyJob" />
            <property name="cronExpression" value="0 0 */1 * * ?" />
        </bean>

             <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                <property name="triggers">
                    <list>
                        <ref bean="monitorOrderStatusAndMoneyTrigger"/>
                    </list>
                </property>
                <property name="autoStartup" value="true"/>
             </bean>
    </beans>

Source download

Guess you like

Origin blog.csdn.net/jlq_diligence/article/details/90255911