parent
23cc7f44be
commit
c96848e9bb
|
@ -6,7 +6,7 @@ import com.alibaba.fastjson2.JSON;
|
|||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.mobai.domain.ApifoxModel;
|
||||
import com.mobai.domain.flux.ApifoxModel;
|
||||
import com.mobai.domain.MqttServerModel;
|
||||
import com.mobai.domain.Result;
|
||||
import com.mobai.service.FluxGetInfoService;
|
||||
|
@ -51,19 +51,41 @@ public class SelectInstances {
|
|||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "0 0/10 * * * ? ")
|
||||
@Scheduled(cron = "0 0/10 * * * ? ")
|
||||
public void saveIps() throws Exception {
|
||||
List<String> ips = new ArrayList<>();
|
||||
|
||||
// 通过接口获取数据
|
||||
public DescribeInstancesResponse getInfo() {
|
||||
DescribeInstancesResponse describeInstancesResponse = null;
|
||||
try {
|
||||
com.aliyun.ecs20140526.Client client = SelectInstances.createClient();
|
||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||
// .setImageId("m-8vb8qnidv34yj3nbirhc")
|
||||
.setRegionId("cn-zhangjiakou");
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
|
||||
describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return describeInstancesResponse;
|
||||
}
|
||||
|
||||
|
||||
//10分钟
|
||||
// @Scheduled(cron = "0 0/10 * * * ? ")
|
||||
//10秒
|
||||
@Scheduled(cron = "0/10 * * * * ? ")
|
||||
public void saveIps() throws Exception {
|
||||
List<String> ips = new ArrayList<>();
|
||||
// com.aliyun.ecs20140526.Client client = SelectInstances.createClient();
|
||||
// com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||
//// .setImageId("m-8vb8qnidv34yj3nbirhc")
|
||||
// .setRegionId("cn-zhangjiakou");
|
||||
// com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
DescribeInstancesResponse response = this.getInfo();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = describeInstancesResponse.getBody().getInstances();
|
||||
// DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = response.getBody().getInstances();
|
||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instance =
|
||||
instances.getInstance();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance inst : instance) {
|
||||
|
@ -102,7 +124,7 @@ public class SelectInstances {
|
|||
for (String ip : ips) {
|
||||
Result<ApifoxModel> info = fluxGetInfoService.getInfo(ip);
|
||||
//连接总数
|
||||
long connectSize = info.getData().getMqttInfo().getConnectSize();
|
||||
long connectSize = Long.parseLong(redisTemplate.opsForValue().get("onlineCar-"+ip));
|
||||
log.info("{}::{}", ip, connectSize);
|
||||
//添加到一个容器
|
||||
nodes.add(new SmallNode(ip, connectSize));
|
||||
|
|
Loading…
Reference in New Issue