Commit 3a86c88d authored by zengtianlai3's avatar zengtianlai3

统计总的在线数量和sam数量

parent 3857c8b5
package iot.sixiang.license.controller;
import iot.sixiang.license.model.SamMonitor;
import iot.sixiang.license.operate.OperateManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* Created by m33 on 2022/6/10 16:43
*/
@Slf4j
@RestController
@RequestMapping("/iot_license/sam")
public class SamMapController {
@Autowired
public OperateManager operateManager;
@GetMapping("count")
public Map<String,Integer> getSamTotalCount() {
Map<String, SamMonitor> samMonitorMap = operateManager.getSamMonitorMap();
Map<String,Integer> map = new HashMap<>();
int totalSamCount = 0;
int totalOnlineCount = 0;
for (SamMonitor samMonitor: samMonitorMap.values()) {
totalSamCount += samMonitor.getSamCount();
totalOnlineCount += samMonitor.getOnlineCount();
}
map.put("totalSamCount",totalSamCount);
map.put("totalOnlineCount",totalOnlineCount);
return map;
}
}
......@@ -43,7 +43,5 @@ public class OperateSAMStatusResponseEventHandler {
samMonitor.setOnlineCount(onlineCount);
samMonitor.setSamCount(samCount);
operateManager.putSamMonitorMap(serverIp, samMonitor);
int allSamCount = 0;
int allOnlineCount = 0;
}
}
......@@ -26,6 +26,10 @@ public class OperateManager {
samMonitorMap = new HashMap<>();
}
public synchronized Map<String, SamMonitor> getSamMonitorMap() {
return samMonitorMap;
}
public synchronized void putSamMonitorMap(String serverIp, SamMonitor samMonitor) {
samMonitorMap.put(serverIp, samMonitor);
}
......
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