简单好用的SLA探活工具 - EaseProbe

作者:matrix 发布时间:2022年10月2日 分类:零零星星

SLA探活的需求很广泛,简单的可以自己实现。但是专门独立的探活工具倒是极少~

EaseProbeGO编写,不需要其他依赖支持直接使用二进制程序运行。

这几天测试用来给api接口、ssl证书、web 200探活,好用~

图片5579-简单好用的SLA探活工具 - EaseProbe

github仓库

https://github.com/megaease/easeprobe

支持HTTP、TCP、SSH、SSL证书、各种数据库/消息中间件服务探活,和email、Slack、Discord、Telegram、飞书...的通知。还支持消息通知和定时发送报表,可以自定义分类告警渠道

配置config.yaml

参照官方配置,新建文件config.yaml

配置SSL证书过期检测、WEB HTTP200检测、接口HTTP状态检测:

http: # http探活

    # 默认监控网页HTTP是否为200OK
  - name: "HHTJIM.COM OK"
    url: https://www.hhtjim.com
  - name: "LINK.HHTJIM.COM OK"
    url: https://www.hhtjim.com

    # 监控接口是否返回指定状态码
  - name: link mp3 parse
    url: https://link.hhtjim.com/163/5146554.mp3
    method: GET
    insecure: true 
    success_code:
        # 配置允许的状态码范围
      - [200,206] # the code >=200 and <= 206
      - [300,308] # the code >=300 and <= 308
    timeout: 1s # default is 30 seconds

tls: # SSL证书探活

    # 监控网页证书是否临近过期(24小时内触发告警)
  - name: "www.hhtjim.com SSL EXPIRED"
    host: www.hhtjim.com:443
    insecure_skip_verify: true # dont check cert validity
    expire_skip_verify: false # dont check cert expire date
    alert_expire_before: 24h # alert if cert expire date is before X, the value is a Duration, see https://pkg.go.dev/time#ParseDuration. example: 1h, 1m, 1s. expire_skip_verify must be false to use this feature.

    # 监控网页证书是否临近过期(7天内触发告警)
  - name: "link.hhtjim.com SSL EXPIRED"
    host: link.hhtjim.com:443
    insecure_skip_verify: true 
    expire_skip_verify: false 
    alert_expire_before: 168h 

notify: # 告警通知方式

  lark:
    - name: "lark alert service"

        # 配置飞书通知机器人的webhook
      webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/00000-10b1-000000-8949-00000000"

# 全局配置
settings:
  probe:
    timeout: 30s # the time out for all probes
    interval: 1m # probe every minute for all probes

说明:

参照上面注释可自由配置,我这里使用的是飞书通知。也可以其他方式告警~

探活配置参数:
https://github.com/megaease/easeprobe/blob/main/docs/Manual.md#1-probe

告警通知配置参数:
https://github.com/megaease/easeprobe/blob/main/docs/Manual.md#2-notification

开启监控

EaseProbe已经有docker镜像,可以直接一键启停。

# 首次启动
$ docker run -d  -p 8181:8181 --name sla -v $(pwd)/config.yaml:/opt/config.yaml megaease/easeprobe


# 重启
$ docker restart sla


# 关闭
$ docker stop sla

查看状态

访问http://HOST:8181`就能看到web监控面板,且支持api接口http://HOST:8181/api/v1/sla`

图片5569-简单好用的SLA探活工具 - EaseProbe

附. 飞书BOT创建

这里的告警通知使用的是群自定义机器人webhook,需要使用飞书客户端创建(web端没有找到入口)

  • 群设置

图片5581-简单好用的SLA探活工具 - EaseProbe

  • 添加自定义机器人

图片5582-简单好用的SLA探活工具 - EaseProbe

  • 复制webhook地址

参考:

https://mp.weixin.qq.com/s/c73ZPBGoMbqjT-xbRiCJ3g

https://github.com/megaease/easeprobe/blob/main/docs/Manual.md

https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN?lang=zh-CN

xiaomi开源SQL优化建议工具 - soar

作者:matrix 发布时间:2018年10月29日 分类:零零星星

SOAR -- sql Optimizer And Rewriter 由小米运维 DBA 团队开发的sql 智能优化与改写工具20181021宣布开源。
github:https://github.com/xiaomi/soar

安装说明:https://github.com/XiaoMi/soar/blob/master/doc/install.md

测试环境:ubuntu 16.04

安装GO

apt-get安装失败改用
源码下载:https://GOlang.GOogle.cn/dl/
配置环境变量

解压:
> sudo tar -C /usr/local -xzf go1.11.1.linux-amd64.tar.gz

全局用户的环境变量:
> sudo vi /etc/profile

末尾添加:
export PATH=$PATH:/usr/local/go/bin

go版本查看:

> go version

source更新环境变量:

source /etc/profile

还需要配置GOPATH环境变量:表示go的工作目录 USER_NAME 为用户名
export GOPATH="/home/USER_NAME/go"

安装soar

> go get -d github.com/XiaoMi/soar
> cd ${GOPATH}/src/github.com/XiaoMi/soar && make

若安装顺利,最终会显示success。否则 build error

我前几次安装都失败

go build github.com/pingcap/tidb/parser: /usr/local/go/pkg/tool/linux_amd64/compile: signal: killed 
Makefile:69: recipe for target 'build' failed

之后google找到帖子 有人说是vps内存太低导致的,遂重启了下Ubuntu 重新make。bingo~

安装成功之后会发现~/go/src/github.com/XiaoMi/soar多出一个 soar文件。
执行测试:

> cd ~/go/src/github.com/XiaoMi/soar
> echo 'select * from film' | ./soar

图片4152-xiaomi开源SQL优化建议工具 - soar

使用soar

常用命令:https://github.com/XiaoMi/soar/blob/master/doc/cheatsheet.md

打印所有的启发式规则1

$ soar -list-heuristic-rules

打印支持的报告格式

$ soar -list-report-types

以指定格式输出报告

$ soar -report-type json

语法检查工具

$ echo "select * from tb" | soar -only-syntax-check
$ echo $?
0

$ echo "select * fromtb" | soar -only-syntax-check
At SQL 0 : syntax error at position 16 near 'fromtb'
$ echo $?
1

慢日志进行分析示例

$ pt-query-digest slow.log > slow.log.digest
# parse pt-query-digest's output which example script
$ python2.7 doc/example/digest_pt.py slow.log.digest > slow.md

SQL指纹

$ echo "select * from film where col='abc'" | soar -report-type=fingerprint

输出

select * from film where col=?

将UPDATE/DELETE/INSERT语法转为SELECT

$ echo "update film set title = 'abc'" | soar -rewrite-rules dml2select,delimiter  -report-type rewrite

输出

select * from film;

合并多条ALTER语句

$ echo "alter table tb add column a int; alter table tb add column b int;" | soar -report-type rewrite -rewrite-rules mergealter

输出

ALTER TABLE `tb` add column a int, add column b int ;

SQL美化

$ echo "select * from tbl where col = 'val'" | ./soar -report-type=pretty

输出

SELECT
  *
FROM
  tbl
WHERE
  col  = 'val';

EXPLAIN信息分析报告

$ soar -report-type explain-digest << EOF
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
|  1 | SIMPLE      | film  | ALL  | NULL          | NULL | NULL    | NULL | 1131 |       |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
EOF
##  Explain信息

| id | select\_type | table | partitions | type | possible_keys | key | key\_len | ref | rows | filtered | scalability | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1  | SIMPLE | *film* | NULL | ALL | NULL | NULL | NULL | NULL | 0 | 0.00% | &#x2620;&#xfe0f; **O(n)** |  |


### Explain信息解读

#### SelectType信息解读

* **SIMPLE**: 简单SELECT(不使用UNION或子查询等).

#### Type信息解读

* &#x2620;&#xfe0f; **ALL**: 最坏的情况, 从头到尾全表扫描.

markdown转HTML

通过指定-report-css, -report-javascript, -markdown-extensions, -markdown-html-flags这些参数,你还可以控制HTML的显示格式。

$ cat test.md | soar -report-type md2html > test.html

PEACE~

参考:
https://github.com/beego/wetalk/issues/32
https://www.oschina.net/news/101034/xiaomi-opensource-soar
https://juejin.im/entry/5bbf21fde51d450e61605d99