Commit 1f2285d5 authored by zengtianlai3's avatar zengtianlai3

监控连接数

parent b0fcf3a4
......@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
/**
......@@ -31,15 +32,8 @@ public class MonitorController {
@GetMapping("list")
public ResResult getMonitorList(@RequestParam("type") int type) {
LocalDate localDate = LocalDate.now();
LocalDate endDate = LocalDate.now();
switch (type) {
case 0: localDate = LocalDate.now();break;
case 1: localDate = localDate.plusDays(-1);break;
case 2: localDate = localDate.plusDays(-6);break;
case 3: localDate = localDate.plusDays(-29);break;
}
List<Monitor> monitorList = monitorService.getMonitorList(localDate, endDate);
HashMap<String,List<Integer>> monitorList = monitorService.getMonitorList(type);
return ResResult.success().record(monitorList);
}
......
......@@ -8,6 +8,7 @@ import iot.sixiang.license.event.DeviceClientLicenseEvent;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientConnectEvent;
import iot.sixiang.license.net.BaseConnectionListener;
import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
......@@ -20,6 +21,8 @@ public class ForwardConnectionListener extends BaseConnectionListener {
@Autowired
private AlarmService alarmService;
@Autowired
private OperateManager operateManager;
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
......@@ -39,7 +42,7 @@ public class ForwardConnectionListener extends BaseConnectionListener {
EventPublisher eventPublisher = SpringUtil.getBean(EventPublisher.class);
eventPublisher.publishEvent(deviceClientBeForcedOfflineEvent);
} else {
operateManager.autoIncrement();
SocketChannel channel = (SocketChannel) channelFuture.channel();
String channelId = channel.id().asLongText();
......
......@@ -7,13 +7,14 @@ import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@Slf4j
//@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
public class JwtFilter implements Filter {
......
......@@ -20,6 +20,7 @@ public class OperateManager {
private Map<String, Server> allServers = null;
private Map<String, SamMonitor> samMonitorMap = null;
private int count = 0;
public OperateManager() {
allServers = new HashMap<String, Server>();
......@@ -42,6 +43,18 @@ public class OperateManager {
return result;
}
public int getCount(){
return this.count;
}
public synchronized void clearCount() {
this.count = 0;
}
public synchronized void autoIncrement() {
this.count++;
}
@PostConstruct
public void init() {
List<Server> servers = serverService.getServerList(0, 20);
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Monitor;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
/**
......@@ -18,5 +19,5 @@ public interface MonitorService extends IService<Monitor> {
boolean addMonitor(int count);
List<Monitor> getMonitorList(LocalDate localDate, LocalDate endDate);
HashMap<String,List<Integer>> getMonitorList(int type);
}
......@@ -9,11 +9,13 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* <p>
* 服务实现类
* 服务实现类
* </p>
*
* @author m33
......@@ -34,7 +36,73 @@ public class MonitorServiceImpl extends ServiceImpl<MonitorMapper, Monitor> impl
}
@Override
public List<Monitor> getMonitorList(LocalDate localDate, LocalDate endDate) {
return monitorMapper.getMonitorList(localDate,endDate);
public HashMap<String,List<Integer>> getMonitorList(int type) {
LocalDate localDate = LocalDate.now();
LocalDate endDate = LocalDate.now();
switch (type) {
case 0:
localDate = LocalDate.now();
break;
case 1:
localDate = localDate.plusDays(-1);
break;
case 2:
localDate = localDate.plusDays(-6);
break;
case 3:
localDate = localDate.plusDays(-29);
break;
}
List<Monitor> monitorList = monitorMapper.getMonitorList(localDate, endDate);
HashMap<Integer, List<Integer>> map = new HashMap<>();
List<Integer> listX = new ArrayList<>();
List<Integer> listY = new ArrayList<>();
if (type == 0 || type == 1) {
for (int i = 0; i < 24; i++) {
int count = 0;
for (Monitor monitor : monitorList) {
Integer hour = monitor.getHour();
if (i == hour) {
count = monitor.getCount();
break;
}
}
listX.add(i);
listY.add(count);
}
} else {
LocalDate now = LocalDate.now();
int end = 0;
if (type == 2) {
end = 7;
} else {
end = 30;
}
for (int i = 0; i < end; i++) {
LocalDate target = now.plusDays(-i);
int count = 0;
for (Monitor monitor : monitorList) {
LocalDate tempDate = monitor.getDate();
if (target.isEqual(tempDate)) {
count = monitor.getCount();
break;
}
}
listX.add(i);
listY.add(count);
}
}
HashMap<String,List<Integer>> maps = new HashMap<>();
maps.put("x",listX);
maps.put("y",listY);
return maps;
}
}
package iot.sixiang.license.util;
import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
......@@ -13,9 +14,14 @@ public class OperateSchedu {
@Autowired
private OperateManager operateManager;
@Autowired
private MonitorService monitorService;
@Scheduled(cron = "0 0 0/1 * * ?")
public void scheduled(){
public void scheduled() {
operateManager.createProxyClient();
int count = operateManager.getCount();
monitorService.addMonitor(count);
operateManager.clearCount();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment