一对多探活器
适用于微服务等含有多个模块的应用做统一探活,主要作用是收敛探活的多个故障告警到产品本身。原理很简单:
把其他需要探活的服务接口(目前只支持 HTTP 和 Socket)配置到这个项目,由它代理对各个服务发起探活检测,最后把各个服务的存活情况聚合返回。
把需要做探活的服务接口配置到 application.yml
,配置方法参考其中的 demo :
# 需要探活的服务列表(格式一)
detected-list:
remoteServices:
- name: "exp"
protocol: "http"
address: "https://exp-blog.com"
- name: "qq"
protocol: "socket"
address: "127.0.0.1:65535"
# 需要探活的服务列表(格式二)
detected-list.remoteServices[2].name: "baidu"
detected-list.remoteServices[2].protocol: "http"
detected-list.remoteServices[2].address: "https://www.baidu.com"
detected-list.remoteServices[3].name: "springboot"
detected-list.remoteServices[3].protocol: "socket"
detected-list.remoteServices[3].address: "127.0.0.1:8080"
运行此项目后,访问 http://localhost:8080/health/liveness 即可查看所有被测服务的结果:
{
"ok": false,
"total": 4,
"errorNum": 1,
"errorData": [
{
"name": "qq",
"protocol": "socket",
"address": "127.0.0.1:65535",
"statusCode": -1,
"statusDesc": "Detecte Error"
}
],
"sussessData": [
{
"name": "exp",
"protocol": "http",
"address": "https://exp-blog.com",
"statusCode": 200,
"statusDesc": ""
},
{
"name": "baidu",
"protocol": "http",
"address": "https://www.baidu.com",
"statusCode": 200,
"statusDesc": ""
},
{
"name": "springboot",
"protocol": "socket",
"address": "127.0.0.1:8080",
"statusCode": 0,
"statusDesc": ""
}
]
}
需注意,http://localhost:8080/health/liveness 接口正常情况下只会有两种状态码:
HTTP 200
: 所有的被测服务均正常HTTP 206
: 部分或所有的被测服务异常
其他状态码均表示
/health/liveness
接口本身的服务异常,但是自身探活建议用/health/self
接口。
本项目以支持容器化,在项目根目录下运行以下脚本即可:
bin/clean.sh
或bin/clean.ps1
: 清理镜像bin/build.sh
或bin/clean.ps1
: 构建镜像bin/deploy.sh
或bin/deploy.ps1
: 发布镜像bin/run.sh
或bin/run.ps1
: 运行容器bin/stop.sh
或bin/stop.ps1
: 停止容器
若需要在容器中修改 application.yml
, 只需把 ./res/apps/one-to-m-liveness/config/application.yml
挂载出来修改即可。
最新镜像已发布到 docker hub :
docker pull expm02/one-to-m-liveness:latest