本篇文章将由我来介绍一款健康/状态检查工具 - Easeprobe 的简单使用。

介绍

EaseProbe 是一个由用 Go 编写的简单、独立、轻量级的工具,可以进行健康/状态检查,

EaseProbe 主要完成3个目标工具: 探测、通知、报告

探测

EaseProbe 支持多种方法来执行其探测,例如:

*  HTTP。检查HTTP状态码,支持mTLS,HTTP Basic Auth,可以设置Request Header/Body。(HTTP 探针配置)
*  TCP。检查是否可以建立 TCP 连接。(TCP 探针配置)
*  shell。运行 Shell 命令并检查结果。(Shell 命令探针配置)
*  SSH。通过 SSH 运行远程命令并检查结果。支持堡垒/跳转服务器(SSH 命令探针配置)
*  TLS。使用 TLS 连接到给定端口并(可选)验证已撤销或过期的证书(TLS 探针配置)
*  Host。在远程主机上运行 SSH 命令并检查 CPU、内存和磁盘使用情况。(主机负载探针)
*  client。支持以下本机客户端。它们都支持 mTLS 和数据检查,请参阅Native Client Probe 配置
    *  MySQL。连接到 MySQL 服务器并运行SHOW STATUSSQL。
    *  Redis。连接到 Redis 服务器并运行PING命令。
    *  Memcache。连接到 Memcache 服务器并运行version命令或验证给定的键/值对。
    *  MongoDB。连接到 MongoDB 服务器并执行 ping。
    *  Kafka。连接到 Kafka 服务器并执行所有主题的列表。
    *  PostgreSQL。连接到 PostgreSQL 服务器并运行SELECT 1SQL。
    *  Zookeeper。连接到 Zookeeper 服务器并运行get /命令。

通知

EaseProbe 支持多种通知方式向你发送通知,例如: slack、钉钉、企业微信、邮件、Telegram 等。

报告和指标

EaseProbe 支持以下报告和指标:

SLA 报告通知。EaseProbe将使用定义的notify:方法发送每日、每周或每月SLA报告。

SLA 实时报告。EaseProbe的默认监听端口为0.0.0.0:8181。通过访问该服务,你将得到实时的SLA报告,可以是HTML格式(http://localhost:8181/), 也可以是 JSON格式(http://localhost:8181/api/v1/sla)。

SLA 数据持久性。默认情况下,SLA 将数据保存在 $CWD/data/data.yaml 。您可以通过编辑配置文件来配置此路径。 更多信息,请查看全局设置配置

普罗米修斯指标。默认情况下,EaseProbe 将侦听8181端口。通过访问此服务,您将获得一些预定义的 Prometheus 指标,地址是http://easeprobe:8181/metrics.

安装

你可以通过下载仓库编译好的程序来使用,也可以自己对源码编译使用。如果你有容器环境也可以使用 megaease/easeprobe 进行docker 部署和 k8s 部署。

本文采用了仓库预编译的程序进行使用。执行 easeprobe -f config.yaml 运行 easeprobe。

接下来我来讲解在我实际使用中用到的配置项。

配置

http 探测

在我的实际使用中,主要使用 http 探测来探测网页是否正常。

http 探测的默认配置如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# http:
#   # A completed HTTP Probe configuration
#   - name: Special Website
#     url: https://megaease.cn
#     # Proxy setting, support sock5, http, https, for example:
#     #   proxy: http://proxy.server:8080
#     #   proxy: socks5://localhost:1085
#     #   proxy: https://user:[email protected]:443
#     # Also support `HTTP_PROXY` & `HTTPS_PROXY` environment variables
#     proxy: http://proxy.server:8080
#     # Request Method
#     method: GET
#     # Request Header
#     headers:
#       User-Agent: Customized User-Agent # default: "MegaEase EaseProbe / v1.6.0"
#       X-head-one: xxxxxx
#       X-head-two: yyyyyy
#       X-head-THREE: zzzzzzX-
#     content_encoding: text/json
#     # Request Body
#     body: '{ "FirstName": "Mega", "LastName" : "Ease", "UserName" : "megaease", "Email" : "[email protected]"}'
#     # HTTP Basic Auth
#     username: username
#     password: password
#     # mTLS
#     ca: /path/to/file.ca
#     cert: /path/to/file.crt
#     key: /path/to/file.key
#     # TLS
#     insecure: true # skip any security checks, useful for self-signed and expired certs. default: false
#     # HTTP successful response code range, default is [0, 499].
#     success_code:
#       - [200,206] # the code >=200 and <= 206
#       - [300,308] # the code >=300 and <= 308
#     # Response Checking
#     contain: "success" # response body must contain this string, if not the probe is considered failed.
#     not_contain: "failure" # response body must NOT contain this string, if it does the probe is considered failed.
#     regex: false # if true, the contain and not_contain will be treated as regular expression. default: false
#     eval: # eval is a expression evaluation for HTTP response message
#       doc: XML # support  XML, JSON, HTML, TEXT.
#       expression: "x_time('//feed/updated') > '2022-07-01'" # the expression to evaluate.
#     # configuration
#     timeout: 10s # default is 30 seconds

可以看到http 探测提供的功能十分丰富,我主要用了简单的状态码判断,和对响应内容判断,我使用的配置如下:

1
2
3
4
5
6
7
  - name: cool 
    url: https://cool.overstarry.vip
    success_code:
      - [ 200,200 ]
  - name: cool version
    url: https://cool.overstarry.vip/version.json
    contain: "\"version\": \"1.0"

第一个探测配置主要是判断网页的状态码,如果状态码不等于 200 就会给我发通知,第二项是判断接口的内容,相当于健康检查。

邮件通知配置

如果探测项发送了改变,我采用邮件来进行通知。具体的配置项如下:

1
2
3
4
5
6
  email:
    - name: "overstarry dev List"
      server: xx:465
      username: [email protected]
      password: xxx
      to: "[email protected];"

多个邮件接收人以分号分隔。

时区设置

在我使用中发现邮件通知中的时间是以 UTC 时区展示的,我通过查看配置文件,发现有一个 timezone 可以设置时区,我将 timezone设置为 “Asia/Shanghai”,但是发现接收到的通知时区还是 UTC ,后来通过查看 issue 得知还需要配置 timeformat: “2006-01-02 15:04:05 Z07:00” 才能正确显示时间。

参考