feat()cpu 内存 负载计算
commit
3f5643fb72
|
@ -0,0 +1,33 @@
|
||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
|
@ -0,0 +1,162 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>parse-message</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>parse-message</name>
|
||||||
|
<description>parse-message</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>11</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<spring-boot.version>2.6.13</spring-boot.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcpkix-jdk15on</artifactId>
|
||||||
|
<version>1.70</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.30</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- servlet 依赖. -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- web -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- http协议 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpcore</artifactId>
|
||||||
|
<version>4.4.12</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.13</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.12.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
|
<version>1.2.5</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- mq-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- json-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.79</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.11</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mybatis 依赖配置 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- PageHelper mybatis分页插件 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
<version>1.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>ecs20140526</artifactId>
|
||||||
|
<version>5.1.8</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.hyc.ParseMessageApplication</mainClass>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>repackage</id>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.hyc;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ParseMessageApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ParseMessageApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.hyc.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rabbitMq配置类
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: RabbitmqConfig
|
||||||
|
* @Description: rabbitMq配置类
|
||||||
|
* @CreateTime: 2024/5/27 16:56
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RabbitmqConfig {
|
||||||
|
public static final String INIT_CONNECT = "init_connect";
|
||||||
|
public static final String DISCONNECT_CONNECT = "disconnect_connect";
|
||||||
|
public static final String EXCHANGE_TOPICS_INFORM="exchange_topics_inform";
|
||||||
|
public static final String ROUTINGKEY_EMAIL="inform.#.email.#";
|
||||||
|
public static final String ROUTINGKEY_SMS="inform.#.sms.#";
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(EXCHANGE_TOPICS_INFORM)
|
||||||
|
public Exchange EXCHANGE_TOPICS_INFORM(){
|
||||||
|
//durable(true) 持久化,mq重启之后交换机还在
|
||||||
|
return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
//声明QUEUE_INFORM_EMAIL队列
|
||||||
|
@Bean(INIT_CONNECT)
|
||||||
|
public Queue QUEUE_INFORM_EMAIL(){
|
||||||
|
return new Queue(INIT_CONNECT);
|
||||||
|
}
|
||||||
|
//声明QUEUE_INFORM_SMS队列
|
||||||
|
@Bean(DISCONNECT_CONNECT)
|
||||||
|
public Queue QUEUE_INFORM_SMS(){
|
||||||
|
return new Queue(DISCONNECT_CONNECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
//ROUTINGKEY_EMAIL队列绑定交换机,指定routingKey
|
||||||
|
@Bean
|
||||||
|
public Binding BINDING_QUEUE_INFORM_EMAIL(@Qualifier(INIT_CONNECT) Queue queue,
|
||||||
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){
|
||||||
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
|
||||||
|
}
|
||||||
|
//ROUTINGKEY_SMS队列绑定交换机,指定routingKey
|
||||||
|
@Bean
|
||||||
|
public Binding BINDING_ROUTINGKEY_SMS(@Qualifier(DISCONNECT_CONNECT) Queue queue,
|
||||||
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){
|
||||||
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.hyc.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rest配置类
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: RestTemplateConfig
|
||||||
|
* @Description: rest配置类
|
||||||
|
* @CreateTime: 2024/5/27 10:01
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
|
||||||
|
return new RestTemplate(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
|
||||||
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||||
|
//超时设置
|
||||||
|
factory.setReadTimeout(5000);//ms
|
||||||
|
factory.setConnectTimeout(15000);//ms
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
//package com.hyc.consumer;
|
||||||
|
//
|
||||||
|
//import com.hyc.domain.ConnectionParameter;
|
||||||
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
|
//import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
//import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * MQTT消费者
|
||||||
|
// *
|
||||||
|
// * @author YouChe·He
|
||||||
|
// * @ClassName: MQTTConsumer
|
||||||
|
// * @Description: MQTT消费者
|
||||||
|
// * @CreateTime: 2024/5/30 19:12
|
||||||
|
// */
|
||||||
|
//@Component
|
||||||
|
//@Slf4j
|
||||||
|
//public class MQTTConsumer {
|
||||||
|
//
|
||||||
|
// public void parseMessage(ConnectionParameter connectionParameter){
|
||||||
|
// int qos = 0;
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// MqttClient client = null;
|
||||||
|
//
|
||||||
|
// client = new MqttClient(connectionParameter.getBroker(), connectionParameter.getClientid(), new MemoryPersistence());
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // 连接参数
|
||||||
|
// MqttConnectOptions options = new MqttConnectOptions();
|
||||||
|
// if (connectionParameter.getUsername() !=null && !"".equals(connectionParameter.getUsername())){
|
||||||
|
// options.setUserName(connectionParameter.getUsername());
|
||||||
|
// options.setPassword(connectionParameter.getPassword().toCharArray());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// options.setConnectionTimeout(60);
|
||||||
|
// options.setKeepAliveInterval(60);
|
||||||
|
// // 设置回调
|
||||||
|
// client.setCallback(new MqttCallback() {
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void connectionLost(Throwable cause) {
|
||||||
|
// System.out.println("connectionLost: " + cause.getMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void messageArrived(String topic, MqttMessage message) {
|
||||||
|
// System.out.println("topic: " + topic);
|
||||||
|
// System.out.println("Qos: " + message.getQos());
|
||||||
|
// System.out.println("message content: " + new String(message.getPayload()));
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void deliveryComplete(IMqttDeliveryToken token) {
|
||||||
|
// System.out.println("deliveryComplete---------" + token.isComplete());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// });
|
||||||
|
// client.connect(options);
|
||||||
|
// client.subscribe(connectionParameter.getTopic(), qos);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
|
@ -0,0 +1,51 @@
|
||||||
|
//package com.hyc.consumer;
|
||||||
|
//
|
||||||
|
//import com.alibaba.fastjson.JSONObject;
|
||||||
|
//import com.hyc.config.RabbitmqConfig;
|
||||||
|
//import com.hyc.domain.ConnectionParameter;
|
||||||
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
|
//import org.springframework.amqp.core.Message;
|
||||||
|
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//
|
||||||
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 断开连接消费者
|
||||||
|
// *
|
||||||
|
// * @author YouChe·He
|
||||||
|
// * @ClassName: ReceiveHandler
|
||||||
|
// * @Description: 断开连接消费者
|
||||||
|
// * @CreateTime: 2024/5/27 17:00
|
||||||
|
// */
|
||||||
|
//@Component
|
||||||
|
//@Slf4j
|
||||||
|
//public class ReceiveHandler {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private MQTTConsumer mqttConsumer;
|
||||||
|
//
|
||||||
|
// @RabbitListener(queues = {RabbitmqConfig.INIT_CONNECT})
|
||||||
|
// public void receive_email(Message msg){
|
||||||
|
// String messageBody = new String(msg.getBody());
|
||||||
|
// ConnectionParameter connectionParameter = getConnectionParameter(messageBody);
|
||||||
|
// mqttConsumer.parseMessage(connectionParameter);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public ConnectionParameter getConnectionParameter(String messageBody){
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// log.error("链接事件得到的消息:{}",messageBody);
|
||||||
|
// JSONObject jsonObject = JSONObject.parseObject(messageBody);
|
||||||
|
// String carVin = jsonObject.getString("clientId");
|
||||||
|
//
|
||||||
|
// String[] split = carVin.split("-");
|
||||||
|
// String vin = split[0];
|
||||||
|
// String broker = split[1];
|
||||||
|
// String topic = split[2];
|
||||||
|
// log.warn("ConnectionParameter对象的属性 broker:{},vin:{},topic:{}",broker,vin,topic);
|
||||||
|
// return new ConnectionParameter(broker,null,null,vin,topic);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.hyc.controller;
|
||||||
|
|
||||||
|
import com.hyc.domain.ConnectionParameter;
|
||||||
|
import com.hyc.domain.SummarizeResp;
|
||||||
|
import com.hyc.result.Result;
|
||||||
|
import com.hyc.service.SummarizeService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建Mqtt客户端
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: CreateMqttClient
|
||||||
|
* @Description: 创建Mqtt客户端
|
||||||
|
* @CreateTime: 2024/5/31 10:25
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/create")
|
||||||
|
public class SummarizeController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SummarizeService summarizeService;
|
||||||
|
|
||||||
|
@PostMapping("/createMqttClient")
|
||||||
|
public String createMqttClient(@RequestBody List<ConnectionParameter> connectionParameterList){
|
||||||
|
|
||||||
|
log.error("进来了!!!");
|
||||||
|
for (ConnectionParameter connectionParameter : connectionParameterList) {
|
||||||
|
boolean oneMqttClient = createOneMqttClient(connectionParameter);
|
||||||
|
if (oneMqttClient==true){
|
||||||
|
log.warn("broker为:{}的mqtt客户端连接成功",connectionParameter.getBroker());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "成功!";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getAllLoadInfo")
|
||||||
|
public Result<SummarizeResp> getAllLoadInfo(){
|
||||||
|
return summarizeService.getAllLoadInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public boolean createOneMqttClient(ConnectionParameter connectionParameter){
|
||||||
|
|
||||||
|
int qos = 0;
|
||||||
|
try {
|
||||||
|
MqttClient client = null;
|
||||||
|
|
||||||
|
client = new MqttClient(connectionParameter.getBroker(), connectionParameter.getClientid(), new MemoryPersistence());
|
||||||
|
|
||||||
|
|
||||||
|
// 连接参数
|
||||||
|
MqttConnectOptions options = new MqttConnectOptions();
|
||||||
|
if (connectionParameter.getUsername() !=null && !"".equals(connectionParameter.getUsername())){
|
||||||
|
options.setUserName(connectionParameter.getUsername());
|
||||||
|
options.setPassword(connectionParameter.getPassword().toCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
options.setConnectionTimeout(60);
|
||||||
|
options.setKeepAliveInterval(60);
|
||||||
|
// 设置回调
|
||||||
|
client.setCallback(new MqttCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectionLost(Throwable cause) {
|
||||||
|
System.out.println("connectionLost: " + cause.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void messageArrived(String topic, MqttMessage message) {
|
||||||
|
System.out.println("topic: " + topic);
|
||||||
|
System.out.println("Qos: " + message.getQos());
|
||||||
|
System.out.println("message content: " + new String(message.getPayload()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||||
|
System.out.println("deliveryComplete---------" + token.isComplete());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
client.connect(options);
|
||||||
|
client.subscribe(connectionParameter.getTopic(), qos);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.hyc.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
/**
|
||||||
|
* 连接MQTT参数
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: ConnectionParameter
|
||||||
|
* @Description: 连接MQTT参数
|
||||||
|
* @CreateTime: 2024/5/30 18:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ConnectionParameter {
|
||||||
|
private String broker;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
private String clientid;
|
||||||
|
private String topic;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.hyc.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务对应负载
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: GetWayServerLoad
|
||||||
|
* @Description: 服务对应负载
|
||||||
|
* @CreateTime: 2024/6/2 22:05
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class GetWayServerLoad {
|
||||||
|
/**
|
||||||
|
* 服务ip
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
/**
|
||||||
|
* 负载率
|
||||||
|
*/
|
||||||
|
private Double loadNum;
|
||||||
|
/**
|
||||||
|
* 内存使用率
|
||||||
|
*/
|
||||||
|
private Double memoryNum;
|
||||||
|
/**
|
||||||
|
* CPU使用率
|
||||||
|
*/
|
||||||
|
private Double cpuNum;
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.hyc.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 概述响应类
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: SummarizeResp
|
||||||
|
* @Description: 概述响应类
|
||||||
|
* @CreateTime: 2024/6/2 16:39
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SummarizeResp {
|
||||||
|
/**
|
||||||
|
* 网管节点收集数量
|
||||||
|
*/
|
||||||
|
private Integer gateWayServerNum;
|
||||||
|
/**
|
||||||
|
* 数据解析节点数量
|
||||||
|
*/
|
||||||
|
private Integer dataAnalyze;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 整体负载
|
||||||
|
*/
|
||||||
|
private Double allLoad;
|
||||||
|
/**
|
||||||
|
* 车辆在线数
|
||||||
|
*/
|
||||||
|
private Integer catOnline;
|
||||||
|
private List<TimeSortCar> timeSortCarList;
|
||||||
|
|
||||||
|
private List<GetWayServerLoad> getWayServerLoadList;
|
||||||
|
|
||||||
|
private List<VinIp> vinIpList;
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.hyc.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间排序小车
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: TimeSortCar
|
||||||
|
* @Description: 时间排序小车
|
||||||
|
* @CreateTime: 2024/6/2 16:34
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class TimeSortCar implements Comparable<TimeSortCar> {
|
||||||
|
/**
|
||||||
|
* 车辆唯一标识 VIN
|
||||||
|
*/
|
||||||
|
private String vin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接节点ip
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
/**
|
||||||
|
* 连接时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date connectTime;
|
||||||
|
/**
|
||||||
|
* 连接时长 单位分钟
|
||||||
|
*/
|
||||||
|
private long connectDuration;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(TimeSortCar o) {
|
||||||
|
return Integer.compare((int) o.connectDuration,(int) this.connectDuration);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.hyc.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小车绑定服务信息
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: VinIp
|
||||||
|
* @Description: 小车绑定服务信息
|
||||||
|
* @CreateTime: 2024/6/2 16:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class VinIp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆唯一标识 VIN
|
||||||
|
*/
|
||||||
|
private String vin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接节点ip
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
/**
|
||||||
|
* 连接时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date connectTime;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.hyc.mapper;
|
||||||
|
/**
|
||||||
|
* 持久层
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: SummarizeMapper
|
||||||
|
* @Description: 持久层
|
||||||
|
* @CreateTime: 2024/6/2 16:47
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.hyc.domain.VinIp;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.web.bind.annotation.Mapping;
|
||||||
|
|
||||||
|
import javax.annotation.ManagedBean;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@ClassName SummarizeMapper
|
||||||
|
*@Description 描述
|
||||||
|
*@Author ZHIHAO.DAI
|
||||||
|
*@Date 2024/6/2 16:47
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SummarizeMapper {
|
||||||
|
|
||||||
|
List<VinIp> getAllLoadInfo();
|
||||||
|
|
||||||
|
List<VinIp> getNewConnectVin();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.hyc.result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回状态码
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class HttpStatus {
|
||||||
|
/**
|
||||||
|
* 操作成功
|
||||||
|
*/
|
||||||
|
public static final int SUCCESS = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象创建成功
|
||||||
|
*/
|
||||||
|
public static final int CREATED = 201;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求已经被接受
|
||||||
|
*/
|
||||||
|
public static final int ACCEPTED = 202;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作已经执行成功,但是没有返回数据
|
||||||
|
*/
|
||||||
|
public static final int NO_CONTENT = 204;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源已被移除
|
||||||
|
*/
|
||||||
|
public static final int MOVED_PERM = 301;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重定向
|
||||||
|
*/
|
||||||
|
public static final int SEE_OTHER = 303;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源没有被修改
|
||||||
|
*/
|
||||||
|
public static final int NOT_MODIFIED = 304;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数列表错误(缺少,格式不匹配)
|
||||||
|
*/
|
||||||
|
public static final int BAD_REQUEST = 400;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未授权
|
||||||
|
*/
|
||||||
|
public static final int UNAUTHORIZED = 401;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 访问受限,授权过期
|
||||||
|
*/
|
||||||
|
public static final int FORBIDDEN = 403;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源,服务未找到
|
||||||
|
*/
|
||||||
|
public static final int NOT_FOUND = 404;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许的http方法
|
||||||
|
*/
|
||||||
|
public static final int BAD_METHOD = 405;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源冲突,或者资源被锁
|
||||||
|
*/
|
||||||
|
public static final int CONFLICT = 409;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不支持的数据,媒体类型
|
||||||
|
*/
|
||||||
|
public static final int UNSUPPORTED_TYPE = 415;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统内部错误
|
||||||
|
*/
|
||||||
|
public static final int ERROR = 500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口未实现
|
||||||
|
*/
|
||||||
|
public static final int NOT_IMPLEMENTED = 501;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统警告消息
|
||||||
|
*/
|
||||||
|
public static final int WARN = 601;
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.hyc.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应信息主体
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Result<T> implements Serializable {
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
public static final int SUCCESS = HttpStatus.SUCCESS;
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*/
|
||||||
|
public static final int FAIL = HttpStatus.ERROR;
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**
|
||||||
|
* 系统警告消息
|
||||||
|
*/
|
||||||
|
private static final int WARN = HttpStatus.WARN;
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static <T> Result<T> success () {
|
||||||
|
return restResult(null, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success (T data) {
|
||||||
|
return restResult(data, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success (T data, String msg) {
|
||||||
|
return restResult(data, SUCCESS, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error () {
|
||||||
|
return restResult(null, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (String msg) {
|
||||||
|
return restResult(null, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (T data) {
|
||||||
|
return restResult(data, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (T data, String msg) {
|
||||||
|
return restResult(data, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (int code, String msg) {
|
||||||
|
return restResult(null, code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn () {
|
||||||
|
return restResult(null, WARN, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (String msg) {
|
||||||
|
return restResult(null, WARN, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (T data) {
|
||||||
|
return restResult(data, WARN, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (T data, String msg) {
|
||||||
|
return restResult(data, WARN, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (int code, String msg) {
|
||||||
|
return restResult(null, code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> Result<T> restResult (T data, int code, String msg) {
|
||||||
|
Result<T> apiResult = new Result<>();
|
||||||
|
apiResult.setCode(code);
|
||||||
|
apiResult.setData(data);
|
||||||
|
apiResult.setMsg(msg);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isError (Result<T> ret) {
|
||||||
|
return !isSuccess(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isSuccess (Result<T> ret) {
|
||||||
|
return Result.SUCCESS == ret.getCode();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.hyc.service;
|
||||||
|
/**
|
||||||
|
* 服务层
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: SummarizeService
|
||||||
|
* @Description: 服务层
|
||||||
|
* @CreateTime: 2024/6/2 16:46
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.hyc.domain.SummarizeResp;
|
||||||
|
import com.hyc.result.Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@ClassName SummarizeService
|
||||||
|
*@Description 描述
|
||||||
|
*@Author ZHIHAO.DAI
|
||||||
|
*@Date 2024/6/2 16:46
|
||||||
|
*/
|
||||||
|
public interface SummarizeService {
|
||||||
|
Result<SummarizeResp> getAllLoadInfo();
|
||||||
|
}
|
|
@ -0,0 +1,191 @@
|
||||||
|
package com.hyc.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.aliyun.ecs20140526.Client;
|
||||||
|
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||||
|
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import com.hyc.domain.GetWayServerLoad;
|
||||||
|
import com.hyc.domain.SummarizeResp;
|
||||||
|
import com.hyc.domain.TimeSortCar;
|
||||||
|
import com.hyc.domain.VinIp;
|
||||||
|
import com.hyc.mapper.SummarizeMapper;
|
||||||
|
import com.hyc.result.Result;
|
||||||
|
import com.hyc.service.SummarizeService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实现
|
||||||
|
*
|
||||||
|
* @author YouChe·He
|
||||||
|
* @ClassName: SummarizeServiceImpl
|
||||||
|
* @Description: 实现
|
||||||
|
* @CreateTime: 2024/6/2 16:46
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SummarizeServiceImpl implements SummarizeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SummarizeMapper summarizeMapper;
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
@Override
|
||||||
|
public Result<SummarizeResp> getAllLoadInfo() {
|
||||||
|
|
||||||
|
ArrayList<GetWayServerLoad> getWayServerLoads = new ArrayList<>();
|
||||||
|
|
||||||
|
Integer carSum = 0;
|
||||||
|
|
||||||
|
Double allLoad = 0.0;
|
||||||
|
|
||||||
|
Integer gateWayServerNum = 0;
|
||||||
|
|
||||||
|
Integer dataAnalyze = 22;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<String> ipList = new ArrayList<>();
|
||||||
|
|
||||||
|
List<VinIp> connectLongVinList = summarizeMapper.getAllLoadInfo();
|
||||||
|
|
||||||
|
List<VinIp> newConnectVinList = summarizeMapper.getNewConnectVin();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
Client client = this.createClient();
|
||||||
|
//填写地区参数和实例规格参数
|
||||||
|
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||||
|
.setRegionId("cn-shanghai")
|
||||||
|
.setInstanceType("ecs.e-c1m2.xlarge");
|
||||||
|
RuntimeOptions runtime = new RuntimeOptions();
|
||||||
|
|
||||||
|
//获得ip并添加进入集合
|
||||||
|
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||||
|
List<List<String>> ipListList = describeInstancesResponse.getBody().instances.getInstance().stream().map(instance -> instance.publicIpAddress.ipAddress).collect(Collectors.toList());
|
||||||
|
for (List<String> strings : ipListList) {
|
||||||
|
for (String ip : strings) {
|
||||||
|
ipList.add(ip);
|
||||||
|
gateWayServerNum ++;
|
||||||
|
}
|
||||||
|
System.out.println("------------------------");
|
||||||
|
}
|
||||||
|
//遍历ip 访问URL
|
||||||
|
for (String ip : ipList) {
|
||||||
|
String url = "http://" + ip + ":8080/public/login";
|
||||||
|
Map<String, Object> request = new HashMap<>();
|
||||||
|
request.put("username", "fluxmq");
|
||||||
|
request.put("password", "fluxmq");
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
HttpEntity<Map<String, Object>> r = new HttpEntity<>(request, httpHeaders);
|
||||||
|
String result = restTemplate.postForObject(url, r, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
//http://fluxmq.muyu.icu/public/cluster
|
||||||
|
|
||||||
|
int nextInt = new Random().nextInt(1000);
|
||||||
|
String getInfoUrl = "http://" + ip + ":8080/public/cluster?random=" + nextInt;
|
||||||
|
|
||||||
|
HttpHeaders httpHeadersGetInfo = new HttpHeaders();
|
||||||
|
httpHeadersGetInfo.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
httpHeadersGetInfo.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||||
|
httpHeadersGetInfo.set("Cookie", result);
|
||||||
|
HttpEntity getInfoRequest = new HttpEntity(httpHeadersGetInfo);
|
||||||
|
ResponseEntity<String> responseInfo = restTemplate.exchange(getInfoUrl, HttpMethod.GET, getInfoRequest, String.class, 1);
|
||||||
|
|
||||||
|
log.info("响应是:{}", responseInfo.getBody());
|
||||||
|
|
||||||
|
JSONArray jsonArray = JSON.parseArray(responseInfo.getBody());
|
||||||
|
if (jsonArray.size() > 0) {
|
||||||
|
|
||||||
|
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||||
|
|
||||||
|
Integer connectSize = Integer.valueOf(jsonObject.getJSONObject("mqttInfo").getString("connectSize"));
|
||||||
|
carSum = connectSize + carSum;
|
||||||
|
log.info("负载:{}",connectSize*1.0/100);
|
||||||
|
|
||||||
|
allLoad = connectSize*1.0/100;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String cSys = jsonObject.getJSONObject("cpuInfo").getString("idle");
|
||||||
|
int i = cSys.indexOf("%");
|
||||||
|
Double cpuInfo = Double.valueOf(cSys.substring(0, i));
|
||||||
|
log.info("CPU利用率:{}",cSys);
|
||||||
|
|
||||||
|
String heapUsed =jsonObject.getJSONObject("jvmInfo").getString("heap-used");
|
||||||
|
int x = heapUsed.indexOf("M");
|
||||||
|
String realHeapUsed = heapUsed.substring(0, x);
|
||||||
|
|
||||||
|
String noHeapUsed = jsonObject.getJSONObject("jvmInfo").getString("no_heap-used");
|
||||||
|
int y = noHeapUsed.indexOf("M");
|
||||||
|
String realNoHeapUsed = noHeapUsed.substring(0, y);
|
||||||
|
|
||||||
|
String heapMax = jsonObject.getJSONObject("jvmInfo").getString("heap-max");
|
||||||
|
int z = heapMax.indexOf("G");
|
||||||
|
String realHeapMax = heapMax.substring(0, z);
|
||||||
|
|
||||||
|
double v = (Double.valueOf(realHeapUsed) + Double.valueOf(realNoHeapUsed))/ (Double.valueOf(realHeapMax) * 1000) * 100;
|
||||||
|
|
||||||
|
BigDecimal bd = new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
double roundedNumber = bd.doubleValue();
|
||||||
|
log.info("heapUsed:{},noHeapUsed:{},heapMax:{},内存使用率:{}",heapUsed,noHeapUsed,heapMax,roundedNumber);
|
||||||
|
getWayServerLoads.add(new GetWayServerLoad(ip,connectSize*1.0/100*100,roundedNumber,cpuInfo));
|
||||||
|
log.info("链接数量:{}", connectSize);
|
||||||
|
} else {
|
||||||
|
log.error("得到的相应数据为null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<TimeSortCar> sortCarArrayList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (VinIp vinIp : connectLongVinList) {
|
||||||
|
Date connectTime = vinIp.getConnectTime();
|
||||||
|
|
||||||
|
Date currentTime = new Date();
|
||||||
|
|
||||||
|
// 计算时间差(单位:毫秒)
|
||||||
|
long timeDifference = currentTime.getTime() - connectTime.getTime();
|
||||||
|
|
||||||
|
// 转换为分钟数
|
||||||
|
long minutesDifference = timeDifference / (1000 * 60);
|
||||||
|
sortCarArrayList.add(new TimeSortCar(vinIp.getVin(),vinIp.getIp(),vinIp.getConnectTime(),minutesDifference));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Collections.sort(sortCarArrayList);
|
||||||
|
SummarizeResp summarizeResp = new SummarizeResp(gateWayServerNum,dataAnalyze,allLoad / gateWayServerNum * 100,carSum,sortCarArrayList,getWayServerLoads,newConnectVinList);
|
||||||
|
|
||||||
|
return Result.success(summarizeResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client createClient() throws Exception {
|
||||||
|
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||||
|
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||||
|
Config config = new Config()
|
||||||
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||||
|
.setAccessKeyId("LTAI5tAEQA9AgnqasQ7Y56cJ")
|
||||||
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||||
|
.setAccessKeySecret("IsrnZ6dKBgEit5HXv2xyfo0xT8VGkj");
|
||||||
|
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||||
|
config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
|
||||||
|
return new Client(config);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
# 服务器相关
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: 10003
|
||||||
|
|
||||||
|
spring:
|
||||||
|
rabbitmq:
|
||||||
|
host: 115.159.47.91
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtualHost: /
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant_path_matcher
|
||||||
|
datasource:
|
||||||
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
|
url: jdbc:mysql://47.103.75.98:3306/netcar?serverTimezone=GMT%2b8&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
|
||||||
|
username: root
|
||||||
|
password: hyc@123
|
||||||
|
druid:
|
||||||
|
# 下面为连接池的补充设置,应用到上面所有数据源中
|
||||||
|
# 初始化大小,最小,最大
|
||||||
|
initial-size: 5
|
||||||
|
min-idle: 5
|
||||||
|
max-active: 20
|
||||||
|
# 配置获取连接等待超时的时间
|
||||||
|
max-wait: 60000
|
||||||
|
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||||
|
time-between-eviction-runs-millis: 60000
|
||||||
|
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||||
|
min-evictable-idle-time-millis: 300000
|
||||||
|
validation-query: SELECT 1 FROM DUAL
|
||||||
|
test-while-idle: true
|
||||||
|
test-on-borrow: false
|
||||||
|
test-on-return: false
|
||||||
|
# 打开PSCache,并且指定每个连接上PSCache的大小
|
||||||
|
pool-prepared-statements: true
|
||||||
|
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
||||||
|
max-pool-prepared-statement-per-connection-size: 20
|
||||||
|
filters: stat,wall
|
||||||
|
use-global-data-source-stat: true
|
||||||
|
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||||
|
connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||||
|
application:
|
||||||
|
name: shop-server
|
||||||
|
redis:
|
||||||
|
host: 47.103.75.98
|
||||||
|
port: 6379
|
||||||
|
password: hyc123
|
||||||
|
|
||||||
|
|
||||||
|
# mybatis
|
||||||
|
mybatis:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
mapper-locations: classpath*:mapper/*Mapper.xml
|
||||||
|
global-config:
|
||||||
|
db-config:
|
||||||
|
id-type: auto
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<!--
|
||||||
|
1.在mybats的开发中namespace有特殊的意思,一定要是对应接口的全限定名
|
||||||
|
通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)
|
||||||
|
-->
|
||||||
|
<mapper namespace="com.hyc.mapper.SummarizeMapper">
|
||||||
|
|
||||||
|
<select id="getAllLoadInfo" resultType="com.hyc.domain.VinIp">
|
||||||
|
SELECT * FROM `vin_ip` ORDER BY connect_time DESC LIMIT 10;
|
||||||
|
</select>
|
||||||
|
<select id="getNewConnectVin" resultType="com.hyc.domain.VinIp">
|
||||||
|
SELECT * FROM `vin_ip` ORDER BY connect_time ASC LIMIT 10;
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.hyc.parsemessage;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class ParseMessageApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue