Skip to content

EXP-Codes/one-to-m-liveness

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

one-to-many liveness

一对多探活器


运行环境

简介

适用于微服务等含有多个模块的应用做统一探活,主要作用是收敛探活的多个故障告警到产品本身。原理很简单:

把其他需要探活的服务接口(目前只支持 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 接口。

容器化

本项目以支持容器化,在项目根目录下运行以下脚本即可:

  1. bin/clean.shbin/clean.ps1: 清理镜像
  2. bin/build.shbin/clean.ps1: 构建镜像
  3. bin/deploy.shbin/deploy.ps1: 发布镜像
  4. bin/run.shbin/run.ps1: 运行容器
  5. bin/stop.shbin/stop.ps1: 停止容器

若需要在容器中修改 application.yml, 只需把 ./res/apps/one-to-m-liveness/config/application.yml 挂载出来修改即可。

最新镜像已发布到 docker hub : docker pull expm02/one-to-m-liveness:latest