Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
83a0b1cd
提交
83a0b1cd
authored
3月 13, 2024
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 新增 health 健康状态检测接口
上级
cef39b03
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
88 行增加
和
8 行删除
+88
-8
HealthController.java
...main/java/com/yiring/app/web/common/HealthController.java
+88
-0
package-info.java
...src/main/java/com/yiring/app/web/common/package-info.java
+0
-8
没有找到文件。
app/src/main/java/com/yiring/app/web/common/HealthController.java
0 → 100644
浏览文件 @
83a0b1cd
/* (C) 2024 YiRing, Inc. */
package
com
.
yiring
.
app
.
web
.
common
;
import
cn.dev33.satoken.annotation.SaIgnore
;
import
com.alibaba.fastjson2.JSONObject
;
import
com.github.xiaoymin.knife4j.annotations.ApiSupport
;
import
com.yiring.auth.domain.user.UserRepository
;
import
com.yiring.common.core.Minio
;
import
com.yiring.common.core.Redis
;
import
com.yiring.common.core.Result
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.servlet.http.HttpServletResponse
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author Jim
*/
@Slf4j
@Validated
@ApiSupport
(
order
=
0
)
@Tag
(
name
=
"健康指标"
,
description
=
"Health"
)
@RequestMapping
(
"/"
)
@RestController
@RequiredArgsConstructor
public
class
HealthController
{
final
ApplicationContext
applicationContext
;
final
Redis
redis
;
final
Minio
minio
;
final
UserRepository
userRepository
;
@SaIgnore
@Operation
(
summary
=
"健康检查"
)
@GetMapping
(
"health"
)
public
Result
<
JSONObject
>
health
(
HttpServletResponse
response
)
{
JSONObject
data
=
new
JSONObject
();
boolean
health
=
true
;
// Redis
try
{
redis
.
info
();
data
.
put
(
"redis"
,
"up"
);
}
catch
(
Exception
e
)
{
data
.
put
(
"redis"
,
"down"
);
health
=
false
;
}
// Database
try
{
userRepository
.
count
();
data
.
put
(
"database"
,
"up"
);
}
catch
(
Exception
e
)
{
data
.
put
(
"database"
,
"down"
);
health
=
false
;
}
// MinIO
try
{
boolean
result
=
minio
.
isValid
();
data
.
put
(
"minio"
,
result
?
"up"
:
"down"
);
}
catch
(
Exception
e
)
{
data
.
put
(
"minio"
,
"down"
);
health
=
false
;
}
// // RabbitMQ
// try {
// rabbitTemplate.send(new Message("health".getBytes()));
// data.put("rabbitmq", "up");
// } catch (Exception e) {
// data.put("rabbitmq", "down");
// health = false;
// }
if
(!
health
)
{
response
.
setStatus
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
}
return
Result
.
ok
(
data
);
}
}
app/src/main/java/com/yiring/app/web/common/package-info.java
deleted
100644 → 0
浏览文件 @
cef39b03
/**
* 公共接口
*
* @author Jim
* @version 0.1
* 2022/6/22 11:30
*/
package
com
.
yiring
.
app
.
web
.
common
;
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论