Commit 1f2285d5 authored by zengtianlai3's avatar zengtianlai3

监控连接数

parent b0fcf3a4
...@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
...@@ -31,15 +32,8 @@ public class MonitorController { ...@@ -31,15 +32,8 @@ public class MonitorController {
@GetMapping("list") @GetMapping("list")
public ResResult getMonitorList(@RequestParam("type") int type) { public ResResult getMonitorList(@RequestParam("type") int type) {
LocalDate localDate = LocalDate.now();
LocalDate endDate = LocalDate.now(); HashMap<String,List<Integer>> monitorList = monitorService.getMonitorList(type);
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);
return ResResult.success().record(monitorList); return ResResult.success().record(monitorList);
} }
......
...@@ -8,6 +8,7 @@ import iot.sixiang.license.event.DeviceClientLicenseEvent; ...@@ -8,6 +8,7 @@ import iot.sixiang.license.event.DeviceClientLicenseEvent;
import iot.sixiang.license.event.EventPublisher; import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientConnectEvent; import iot.sixiang.license.event.ForwardClientConnectEvent;
import iot.sixiang.license.net.BaseConnectionListener; import iot.sixiang.license.net.BaseConnectionListener;
import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.AlarmService; import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.util.SpringUtil; import iot.sixiang.license.util.SpringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,6 +21,8 @@ public class ForwardConnectionListener extends BaseConnectionListener { ...@@ -20,6 +21,8 @@ public class ForwardConnectionListener extends BaseConnectionListener {
@Autowired @Autowired
private AlarmService alarmService; private AlarmService alarmService;
@Autowired
private OperateManager operateManager;
@Override @Override
public void operationComplete(ChannelFuture channelFuture) throws Exception { public void operationComplete(ChannelFuture channelFuture) throws Exception {
...@@ -39,7 +42,7 @@ public class ForwardConnectionListener extends BaseConnectionListener { ...@@ -39,7 +42,7 @@ public class ForwardConnectionListener extends BaseConnectionListener {
EventPublisher eventPublisher = SpringUtil.getBean(EventPublisher.class); EventPublisher eventPublisher = SpringUtil.getBean(EventPublisher.class);
eventPublisher.publishEvent(deviceClientBeForcedOfflineEvent); eventPublisher.publishEvent(deviceClientBeForcedOfflineEvent);
} else { } else {
operateManager.autoIncrement();
SocketChannel channel = (SocketChannel) channelFuture.channel(); SocketChannel channel = (SocketChannel) channelFuture.channel();
String channelId = channel.id().asLongText(); String channelId = channel.id().asLongText();
......
...@@ -7,13 +7,14 @@ import iot.sixiang.license.model.ResResult; ...@@ -7,13 +7,14 @@ import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@Slf4j @Slf4j
//@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*") @WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
public class JwtFilter implements Filter { public class JwtFilter implements Filter {
......
...@@ -20,6 +20,7 @@ public class OperateManager { ...@@ -20,6 +20,7 @@ public class OperateManager {
private Map<String, Server> allServers = null; private Map<String, Server> allServers = null;
private Map<String, SamMonitor> samMonitorMap = null; private Map<String, SamMonitor> samMonitorMap = null;
private int count = 0;
public OperateManager() { public OperateManager() {
allServers = new HashMap<String, Server>(); allServers = new HashMap<String, Server>();
...@@ -42,6 +43,18 @@ public class OperateManager { ...@@ -42,6 +43,18 @@ public class OperateManager {
return result; return result;
} }
public int getCount(){
return this.count;
}
public synchronized void clearCount() {
this.count = 0;
}
public synchronized void autoIncrement() {
this.count++;
}
@PostConstruct @PostConstruct
public void init() { public void init() {
List<Server> servers = serverService.getServerList(0, 20); List<Server> servers = serverService.getServerList(0, 20);
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Monitor; import iot.sixiang.license.entity.Monitor;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
...@@ -18,5 +19,5 @@ public interface MonitorService extends IService<Monitor> { ...@@ -18,5 +19,5 @@ public interface MonitorService extends IService<Monitor> {
boolean addMonitor(int count); boolean addMonitor(int count);
List<Monitor> getMonitorList(LocalDate localDate, LocalDate endDate); HashMap<String,List<Integer>> getMonitorList(int type);
} }
...@@ -9,6 +9,8 @@ import org.springframework.stereotype.Service; ...@@ -9,6 +9,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
...@@ -34,7 +36,73 @@ public class MonitorServiceImpl extends ServiceImpl<MonitorMapper, Monitor> impl ...@@ -34,7 +36,73 @@ public class MonitorServiceImpl extends ServiceImpl<MonitorMapper, Monitor> impl
} }
@Override @Override
public List<Monitor> getMonitorList(LocalDate localDate, LocalDate endDate) { public HashMap<String,List<Integer>> getMonitorList(int type) {
return monitorMapper.getMonitorList(localDate,endDate); 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; package iot.sixiang.license.util;
import iot.sixiang.license.operate.OperateManager; import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -13,9 +14,14 @@ public class OperateSchedu { ...@@ -13,9 +14,14 @@ public class OperateSchedu {
@Autowired @Autowired
private OperateManager operateManager; private OperateManager operateManager;
@Autowired
private MonitorService monitorService;
@Scheduled(cron = "0 0 0/1 * * ?") @Scheduled(cron = "0 0 0/1 * * ?")
public void scheduled(){ public void scheduled() {
operateManager.createProxyClient(); 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