AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
我们以前面编写的用户微服务为例,非会员用户请先下载上个实验用户微服务的代码包: (如果对会员保存环境等服务感兴趣,欢迎去会员页面了解详情:[vip](https://www.lanqiao.cn/vip)) ~~~bash wget https://labfile.oss.aliyuncs.com/courses/1360/microservice-provider-user-2.zip unzip microservice-provider-user-2.zip cd microservice-provider-user ~~~ * 引用依赖 ~~~xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ~~~ * 通过 mvn 运行程序: ~~~bash mvn spring-boot:run ~~~ 如果你想要查看该服务的相关监控信息,只需以`http://{ip}:{port}/actuator/{endpoint}`方式访问端点即可。 * 测试: /health 端点 ~~~bash curl http://localhost:8000/actuator/health ~~~ 将会看到如下响应: ~~~json { "status": "UP" } ~~~ * 测试:/health 端点展示详情 首先我们需要为`/health`端点添加显示详情的配置,我们需要修改`resources/application.yml`文件,加入以下内容: ~~~yaml management: endpoint: health: # 是否展示健康检查详情 show-details: always ~~~ 我们停掉程序重新启动: ~~~bash mvn spring-boot:run ~~~ 此时,我们再次访问`http://localhost:8000/actuator/health`: ~~~bash curl http://localhost:8000/actuator/health ~~~ 可以看到如下响应: ~~~json { "status": "UP", "details": { "db": { "status": "UP", "details": { "database": "H2", "hello": 1 } }, "diskSpace": { "status": "UP", "details": { "total": 250685575168, "free": 23969091584, "threshold": 10485760 } } } } ~~~ 提示:如果你想暴露所有监控端点可以参考如下配置: ~~~yml management: endpoints: web: exposure: include: '*' ~~~