admin
2020-08-26 26f7accb815f55f18f8eedfca4324700a96884ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.yeshi.fanli.controller;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
 
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.yeshi.fanli.service.inter.common.DataMonitorService;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.NetWorkUtil;
 
/**
 * 监控
 *
 * @author Administrator
 */
@Controller
@RequestMapping("monitor")
public class MonitorController {
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private DataMonitorService dataMonitorService;
 
    /**
     * 10分钟外没爬单就判断为异常
     *
     * @param out
     */
    @RequestMapping("getTaoBaoOrderParseState")
    public void getTaoBaoOrderParseState(HttpServletResponse response, PrintWriter out) {
        Date date = dataMonitorService.getLatestParseTaoBaoOrderSuccessTime();
        // 10分钟做判断
        if (date != null && (Math.abs(date.getTime() - System.currentTimeMillis())) < 1000 * 60 * 10) {
            out.print(JsonUtil.loadTrueResult(""));
            return;
        } else {
            try {
                response.sendError(666, "订单爬取疑似有问题");
                return;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
    /**
     * zookeeper服务
     */
    @RequestMapping("zookeeper")
    public void zookeeper(HttpServletResponse response, PrintWriter out) {
        if (NetWorkUtil.isHostConnectable("134.175.68.214", 2181, 2000)) {
            out.print("200");
        } else {
            try {
                response.sendError(666, "异常");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
 
    }
 
    /**
     * 商品服务
     */
    @RequestMapping("dubboGoodsService")
    public void dubboGoodsService(HttpServletResponse response, PrintWriter out) {
        if (NetWorkUtil.isHostConnectable("134.175.68.214", 20882, 2000)) {
            out.print("200");
        } else {
            try {
                response.sendError(666, "异常");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
    /**
     * 订单爬取是否正常
     * @param platform
     * @return
     */
    private boolean isParseOrderNormal(String platform) {
        String st = redisManager.getCommonString(RedisKeyEnum.monitor.getKey() + platform);
        if (StringUtil.isNullOrEmpty(st)) {
            return false;
        }
        return true;
    }
 
 
    /**
     * 订单解析是否正常
     * @param sourceType
     * @param response
     * @param out
     */
    @RequestMapping("orderParse")
    public void orderParse(int sourceType, HttpServletResponse response, PrintWriter out) {
        if (isParseOrderNormal(sourceType+"")) {
            out.print("200");
        } else {
            try {
                response.sendError(666, "异常");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
 
 
 
}