在Ubuntu系統中監控Swagger接口,可以通過以下幾種方法:
Swagger UI是一個用于可視化API文檔和測試API的工具。你可以使用Swagger UI來查看和測試你的Swagger接口。
你可以通過npm安裝Swagger UI:
sudo apt update
sudo apt install nodejs npm
sudo npm install -g swagger-ui-express
在你的Spring Boot應用中,添加Swagger依賴并配置Swagger:
<!-- 在pom.xml中添加Swagger依賴 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
配置Swagger:
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo"))
.paths(PathSelectors.any())
.build();
}
}
啟動應用后,訪問http://localhost:8080/swagger-ui.html
即可看到Swagger UI界面。
Postman是一個強大的API測試工具,可以用來發送HTTP請求并查看響應。
你可以從Postman官網下載并安裝Postman。
如果你想監控網絡流量,可以使用tcpdump或Wireshark來捕獲和分析HTTP請求和響應。
sudo tcpdump -i any port 8080 -w http_traffic.pcap
eth0
)。http
Spring Boot Actuator提供了許多生產就緒的功能,包括監控和管理應用。
在pom.xml
中添加以下依賴:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在application.properties
中啟用所有端點:
management.endpoints.web.exposure.include=*
啟動應用后,訪問http://localhost:8080/actuator
即可看到所有可用的端點。
通過以上方法,你可以在Ubuntu系統中監控Swagger接口。選擇適合你需求的方法進行操作即可。