Authored by htoooth

add sql

@@ -21,7 +21,6 @@ function errorRouter(m) { @@ -21,7 +21,6 @@ function errorRouter(m) {
21 app: _.get(m, 'tags.app', ''), 21 app: _.get(m, 'tags.app', ''),
22 type: _.get(m, 'tags.type', ''), 22 type: _.get(m, 'tags.type', ''),
23 hostname: _.get(m, 'tags.hostname', ''), 23 hostname: _.get(m, 'tags.hostname', ''),
24 - preqid: _.get(m, 'tags.preqid', ''),  
25 reqid: _.get(m, 'tags.reqID', ''), 24 reqid: _.get(m, 'tags.reqID', ''),
26 uid: _.get(m, 'tags.uid', ''), 25 uid: _.get(m, 'tags.uid', ''),
27 route: _.get(m, 'tags.route', ''), 26 route: _.get(m, 'tags.route', ''),
@@ -75,7 +75,7 @@ const server = { @@ -75,7 +75,7 @@ const server = {
75 }; 75 };
76 76
77 module.exports = function(req, res, next) { 77 module.exports = function(req, res, next) {
78 - let data = req.body || ''; 78 + let data = req.body || ' ';
79 79
80 server.handle(data).then(() => { 80 server.handle(data).then(() => {
81 res.status(204).json(); 81 res.status(204).json();
1 -CREATE EVENT `e_del_slow_route`  
2 -ON SCHEDULE EVERY 1 DAY STARTS '2017-12-3 0:0:0'  
3 -ON COMPLETION NOT PRESERVE ENABLE DO CALL p_del_slow (7);  
4 -  
5 -CREATE EVENT `e_del_error_report`  
6 -ON SCHEDULE EVERY 1 DAY STARTS '2017-12-3 0:0:0'  
7 -ON COMPLETION NOT PRESERVE ENABLE DO CALL p_del_error (7); 1 +-- 连接mysql
  2 +mysql -h 192.168.102.168 -u root -proot webapm
8 3
9 -p_del_slow 4 +--创建存储过程
10 DELIMITER $$ 5 DELIMITER $$
11 CREATE PROCEDURE `p_del_slow`(IN `date_inter` INT) 6 CREATE PROCEDURE `p_del_slow`(IN `date_inter` INT)
12 BEGIN 7 BEGIN
13 - DELETE FROM slow_duration WHERE (TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(create_time)))>=date_inter; 8 + DELETE FROM slow_duration WHERE (TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(create_time/1000)))>=date_inter;
14 END$$ 9 END$$
15 DELIMITER ; 10 DELIMITER ;
16 11
17 -  
18 -p_del_error  
19 DELIMITER $$ 12 DELIMITER $$
20 CREATE PROCEDURE `p_del_error`(IN `date_inter` INT) 13 CREATE PROCEDURE `p_del_error`(IN `date_inter` INT)
21 BEGIN 14 BEGIN
22 - DELETE FROM error_report WHERE (TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(create_time)))>=date_inter; 15 + DELETE FROM error_report WHERE (TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(create_time/1000)))>=date_inter;
  16 +END$$
  17 +DELIMITER ;
  18 +
  19 +-- test
  20 +DELIMITER $$
  21 +CREATE PROCEDURE `i_sert`(IN `date_inter` INT)
  22 +BEGIN
  23 + INSERT INTO slow_duration(route) values('huangtao');
23 END$$ 24 END$$
24 -DELIMITER ;  
  25 +DELIMITER ;
  26 +
  27 +-- 删除存储过程
  28 +drop procedure if exists p_del_error;
  29 +
  30 +-- 列出所有存储过程
  31 +select specific_name from mysql.proc;
  32 +
  33 +-- 查看某一个存储过程的具体内容
  34 +select body from mysql.proc where specific_name = 'p_del_slow';
  35 +
  36 +-- 调用存储过程
  37 +call p_del_slow();
  38 +
  39 +-- 查看定时配置开启
  40 +show variables like '%event_sche%';
  41 +set global event_scheduler=1;
  42 +
  43 +-- 创建定时任务
  44 +CREATE EVENT `e_del_slow_route`
  45 +ON SCHEDULE EVERY 1 DAY STARTS '2017-12-7 0:0:0'
  46 +ON COMPLETION PRESERVE DISABLE
  47 +DO CALL p_del_slow (7);
  48 +
  49 +CREATE EVENT `e_del_error_report`
  50 +ON SCHEDULE EVERY 1 DAY STARTS '2017-12-7 0:0:0'
  51 +ON COMPLETION PRESERVE DISABLE
  52 +DO CALL p_del_error (7);
  53 +
  54 +-- test
  55 +CREATE EVENT `i_second`
  56 +ON SCHEDULE EVERY 1 SECOND
  57 +ON COMPLETION PRESERVE DISABLE
  58 +DO CALL i_sert (7);
  59 +
  60 +-- 数目
  61 +select count(*) from slow_duration;
  62 +
  63 +--查看本机所有的事件
  64 +SELECT event_name,event_definition,interval_value,interval_field,status FROM information_schema.EVENTS;
  65 +
  66 +--开启定时任务
  67 +alter event e_del_slow_route on completion preserve enable;
  68 +alter event e_del_error_report on completion preserve enable;
  69 +
  70 +--关闭定时任务
  71 +alter event e_del_slow_route on completion preserve disable;
  72 +alter event e_del_error_report on completion preserve disable;
  73 +
  74 +--删除存储过程
  75 +drop event if exists e_del_slow_route;
  76 +drop event if exists e_del_error_report;
  77 +
  78 +-- http://jiyiren.github.io/2016/03/27/Mysql_schedule/
  79 +