Merge branch 'master' into docker_package
This commit is contained in:
commit
45cf2f747f
|
@ -48,7 +48,7 @@ public class MonitorController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RestTemplate restTemplate;
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
@Value("${hisense.gateway.url}")
|
@Value("${hisense.gateway.dp-url}")
|
||||||
private String gatewayDomain;
|
private String gatewayDomain;
|
||||||
|
|
||||||
@Value("${server.servlet.context-path}")
|
@Value("${server.servlet.context-path}")
|
||||||
|
|
|
@ -35,6 +35,8 @@ import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@Api(tags = "网关统计")
|
@Api(tags = "网关统计")
|
||||||
|
@ -42,10 +44,12 @@ import java.util.*;
|
||||||
@RequestMapping("/gateway-monitor/v2")
|
@RequestMapping("/gateway-monitor/v2")
|
||||||
public class MonitorControllerV2 {
|
public class MonitorControllerV2 {
|
||||||
|
|
||||||
|
private static final ExecutorService executor = Executors.newFixedThreadPool(35);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RestTemplate restTemplate;
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
@Value("${hisense.gateway.url}")
|
@Value("${hisense.gateway.dp-url}")
|
||||||
private String gatewayDomain;
|
private String gatewayDomain;
|
||||||
|
|
||||||
@Value("${server.servlet.context-path}")
|
@Value("${server.servlet.context-path}")
|
||||||
|
@ -65,9 +69,67 @@ public class MonitorControllerV2 {
|
||||||
|
|
||||||
@GetMapping("/queryGroupByAbility")
|
@GetMapping("/queryGroupByAbility")
|
||||||
@ApiOperation("统计数据按能力归集")
|
@ApiOperation("统计数据按能力归集")
|
||||||
public Result queryGroupByAbility(String query, String time){
|
public Result queryGroupByAbility(String query, String time) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
String url = gatewayDomain + "/juapi/metrics/api/v1/query?query={query}" + "&time=" + time;
|
|
||||||
ResponseEntity<HashMap> entity = restTemplate.getForEntity(url, HashMap.class, query);
|
String url = gatewayDomain + "/juapi/metrics/api/v1/query?query={query}&time={time}";
|
||||||
|
List<String> querys = new ArrayList<>();
|
||||||
|
List<CompletableFuture<List<?>>> futures = querys.stream().map(item -> {
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
|
||||||
|
ResponseEntity<HashMap> entity = restTemplate.getForEntity(url, HashMap.class, query, time);
|
||||||
|
/** 接口数据示例
|
||||||
|
* {
|
||||||
|
* "status": "success",
|
||||||
|
* "data": {
|
||||||
|
* "resultType": "vector",
|
||||||
|
* "result": [
|
||||||
|
* {
|
||||||
|
* "metric": {
|
||||||
|
* "groupInfo": "group10"
|
||||||
|
* },
|
||||||
|
* "value": [
|
||||||
|
* 1660636097,
|
||||||
|
* "0"
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
HashMap body = entity.getBody();
|
||||||
|
HashMap data = (HashMap) body.get("data");
|
||||||
|
if (data != null) {
|
||||||
|
List<HashMap> result = (List) data.get("result");
|
||||||
|
ArrayList<Map> results = new ArrayList<>();
|
||||||
|
for (HashMap hashMap : result) {
|
||||||
|
Map metric = (Map) hashMap.get("metric");
|
||||||
|
List value = (List) hashMap.get("value");
|
||||||
|
if (metric == null || metric.get("groupInfo") == null || value == null || value.size() != 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Long groupInfo = Long.valueOf((String) metric.get("groupInfo"));
|
||||||
|
metric.put("groupInfo", groupInfo);
|
||||||
|
results.add(metric);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//忽略
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}, executor);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
HashMap<String, Map<String, Object>> filterMap = new HashMap<String, Map<String, Object>>();
|
||||||
|
for (CompletableFuture<List<?>> future : futures) {
|
||||||
|
List<Map<String, Object>> list = (List<Map<String, Object>>) future.get(30, TimeUnit.SECONDS);
|
||||||
|
list.forEach(item -> {
|
||||||
|
filterMap.containsKey(item.)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ResponseEntity<HashMap> entity = restTemplate.getForEntity(url, HashMap.class, query, time);
|
||||||
HashMap body = entity.getBody();
|
HashMap body = entity.getBody();
|
||||||
HashMap data = (HashMap) body.get("data");
|
HashMap data = (HashMap) body.get("data");
|
||||||
if (data != null){
|
if (data != null){
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
@Service
|
@Service
|
||||||
public class MonitorServiceV2 {
|
public class MonitorServiceV2 {
|
||||||
|
|
||||||
@Value("${hisense.gateway.url}")
|
@Value("${hisense.gateway.dp-url}")
|
||||||
private String gatewayDomain;
|
private String gatewayDomain;
|
||||||
|
|
||||||
@Value("${hisense.gateway.sync-enabled}")
|
@Value("${hisense.gateway.sync-enabled}")
|
||||||
|
|
|
@ -50,7 +50,9 @@ big_date:
|
||||||
|
|
||||||
hisense:
|
hisense:
|
||||||
gateway:
|
gateway:
|
||||||
url: http://15.72.184.7:8080
|
sync-enabled: true
|
||||||
|
url: http://15.72.184.3:30479
|
||||||
|
dp-url: http://15.72.184.3:31230
|
||||||
|
|
||||||
|
|
||||||
qdyjj:
|
qdyjj:
|
||||||
|
|
|
@ -18,6 +18,7 @@ hisense:
|
||||||
gateway:
|
gateway:
|
||||||
sync-enabled: true
|
sync-enabled: true
|
||||||
url: http://devtest-security-app.hismarttv.com:8080
|
url: http://devtest-security-app.hismarttv.com:8080
|
||||||
|
dp-url: http://devtest-security-app.hismarttv.com:8080
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
tomcat:
|
tomcat:
|
||||||
|
|
Loading…
Reference in New Issue