1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.landtool.lanbase.common;
 
import java.io.IOException;
import java.net.*;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
 
import com.landtool.lanbase.common.utils.ShiroUtils;
import com.landtool.lanbase.modules.sys.entity.SysSystemProblemTrack;
import com.landtool.lanbase.modules.sys.entity.SysSysteminfo;
import com.landtool.lanbase.modules.sys.redis.OnlineUserRedis;
import com.landtool.lanbase.modules.sys.service.impl.MonitorServiceImpl;
 
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.shiro.session.mgt.SessionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import com.landtool.lanbase.config.WebSocketServer;
import com.landtool.lanbase.modules.sys.controller.SecModController;
 
@Component
@Configuration
@EnableScheduling
public class ScheduleTask {
 
    private  Logger log=LoggerFactory.getLogger(ScheduleTask.class);
    @Autowired
    public SecModController secModController;
    @Autowired
    public MonitorServiceImpl monitorService;
    @Autowired
    private OnlineUserRedis onlineUserRedis;
    
    @Scheduled(fixedRate=10*1000)
    public void     pushMonitorInfo() throws InterruptedException {
        //人员在线状态
        String onlineUser=secModController.queryonlineUser();
 
        String serverinfo=secModController.serverstatus();
        String errorSystem=secModController.queryErrorSystem(null,null);
        //用户使用行为
        
        //服务资源状态
        
        //服务资源调用情况
        try {
            WebSocketServer.BroadCastInfo(onlineUser);
            WebSocketServer.BroadCastInfo(serverinfo);
            WebSocketServer.BroadCastInfo(errorSystem);
        
        } catch (IOException e) {
            log.error("WEBSOCKET PUSHH ERROR"+e.toString());
            e.printStackTrace();
        }
        
    }
    
 
//    @Scheduled(fixedRate=10*1000)
//    public void     removeDownlineUser() throws InterruptedException {
//    //    onlineUserRedis.removeDownlineUser();
//    }
    
 
    @Scheduled(fixedRate=100*1000)
    public void     checkSystemStatus() throws InterruptedException {
        Map<String,Object> map=new HashMap<>();
        List<SysSysteminfo> sysSysteminfos=monitorService.querySysSystemInfo(map);
        sysSysteminfos.forEach(new Consumer<SysSysteminfo>() {
            @Override
            public void accept(SysSysteminfo sysSysteminfo) {
                Socket s=new Socket();
                //ping通地址
                try {
                    URI uri=new URI(sysSysteminfo.getSysaddress());
                    SocketAddress add=new InetSocketAddress(uri.getHost(),uri.getPort()==-1?80:uri.getPort());
                    s.connect(add,5000);
                } catch ( IOException e) {
                    log.debug(sysSysteminfo.getSysaddress()+"服务异常"+e.getMessage());
                    //此处更新系统状态记录表
                    SysSystemProblemTrack sysSystemProblemTrack=new SysSystemProblemTrack();
                    sysSystemProblemTrack.setAppid(sysSysteminfo.getAppid());
                    sysSystemProblemTrack.setAddress(sysSysteminfo.getSysaddress());
                    sysSystemProblemTrack.setStatus("fail");
                    sysSystemProblemTrack.setCreatetime(Timestamp.valueOf(LocalDateTime.now()));
                    sysSystemProblemTrack.setProblemreason("网络问题");
                    monitorService.insertSystemProblem(sysSystemProblemTrack);
 
            
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        s.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
 
            }
        });
 
    }
 
    
 
 
//    @Scheduled(fixedRate=360*1000)
//    public void     checkSystemStatus() throws InterruptedException {
//        Map<String,Object> map=new HashMap<>();
//        List<SysSysteminfo> sysSysteminfos=monitorService.querySysSystemInfo(map);
//        sysSysteminfos.forEach(new Consumer<SysSysteminfo>() {
//            @Override
//            public void accept(SysSysteminfo sysSysteminfo) {
//
//                //ping通地址
//                try {
//                    URI uri=new URI(sysSysteminfo.getSysaddress());
//                    CloseableHttpClient httpClient=HttpClients.createDefault();
//                    HttpGet get=new HttpGet(sysSysteminfo.getSysaddress());
//                    HttpResponse httpResponse=httpClient.execute(get);
//                    if(httpResponse.getStatusLine().getStatusCode()!=200){
//                        SysSystemProblemTrack sysSystemProblemTrack=new SysSystemProblemTrack();
//                        sysSystemProblemTrack.setAppid(sysSysteminfo.getAppid());
//                        sysSystemProblemTrack.setAddress(sysSysteminfo.getSysaddress());
//                        sysSystemProblemTrack.setStatus("fail");
//                        sysSystemProblemTrack.setProblemreason("网络问题:"+httpResponse.getStatusLine().getStatusCode()+httpResponse.getEntity().getContent());
//                        monitorService.insertSystemProblem(sysSystemProblemTrack);
//                    }
//                } catch ( IOException e) {
//                    //此处更新系统状态记录
//                    e.printStackTrace();
//                } catch (URISyntaxException e) {
//                    e.printStackTrace();
//                } finally {
//                    try {
//                        s.close();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                }
//
//            }
//        });
//
//    }
}