catpaw体验-轻量级告警监控上
  veRHuRoEnYSe 2023年11月02日 73 0

前言

这两天看到SRETalk公众号的秦总,写了个新工具太卷了,史上最简单的监控系统 catpaw 简介,而且目前最新版还提供硬件监控的能力机器硬件监控,最简单的方案,没有之一 ,看上去挺厉害的,特地来体验这个轻量级告警监控的工具,上手把玩一下看看咋样。

使用介绍

使用起来其实还挺简单,所需要准备:

  1. 部署catepaw

catepaw 直在目标机器上采集告警事件,启动前修改对应配置,插件配置。

catpaw 不能取代指标监控和日志系统,它只是一个轻量的 check 工具,一些场景举例:

  • 探测某个 HTTP 地址,如果不可用,把不可用的原因发出来
  • 探测某个 TCP 地址,如果不可用,把不可用的原因发出来
  • 探测某个文件,如果文件不存在,或者 MD5 发生变化,发出告警事件
  • 探测 ulimit 配置,如果发现不合理,发出告警事件
  • 探测目录是否可读可写,如果异常发出告警事件
  • 探测是否有目录已写满,如果写满的目录,发出告警事件,把 df -h 的结果一并发出来
  • 探测某个进程是否存在,如果不存在,发出告警事件
  • 探测 MySQL 慢查询,如果发现慢SQL,发出告警事件,事件中带上SQL
  • 探测 MySQL 主从延迟,如果延迟超过阈值,发出告警事件,事件中带上延迟时间以及两个 Thread 的情况
  • 接收 SNMP Trap 消息,如果消息中包含某个关键字,发出告警事件
  • 检查系统日志,如果出现某个关键字,告警,把日志详情一并发出来
  • ….

更多场景不再赘述,其特点基本上可以概括为:

  • check 的时候已经可以知道是否正常
  • check 的时候大概率可以拿到异常原因或者现场值,把这些信息一并发出来
  1. 注册个 FlashDuty 账号

catepaw 需要配置 FlashDuty 推送 url ,把异常事件推送给 FlashDuty ,在 FlashDuty 中对告警进行处理。 注册个免费账号,告警接入选择‘自定义事件’,然后把接口 url 填到catepaw的 config.toml 中。注册目前是两周的全功能免费。

flashduty.url 需要去 FlashDuty 获取,地址在这里:https://console.flashcat.cloud/,可以免费注册,注册之后,系统会自动引导你创建一个协作空间,然后在协作空间下,添加告警接入专属集成就可以了

可用插件

目前最新版是catpaw-v0.4.0-linux-amd64,目录结构如下

./
|-- catpaw*
|-- conf.d/
|   |-- config.toml
|   |-- p.exec/
|   |-- p.http/
|   |-- p.journaltail/
|   |-- p.mtime/
|   |-- p.net/
|   `-- p.sfilter/
`-- scripts/
    |-- demo.sh*
    |-- greplog.sh*
    `-- ulimit.sh*

可以看到目前提供了 exec 插件,http 插件,journaltail 插件,mtime 插件,net 插件,sfiler 插件。盲猜插件禁用删除(改名)对应配置文件就行。

  • exec 插件

exec 插件是指行脚本文件,scripts 目录下的样例脚本。

more scripts/ulimit.sh
#!/bin/sh

if [ "$1" ]; then
    threshhold=$1
else
    threshhold=2048
fi

count=$(ulimit -n)

status="Ok"
if [ $count -lt $threshhold ]; then
    status="Warning"
fi

echo '[
    {
        "event_status": "'${status}'",
        "labels": {
            "check": "ulimit check"
        },
        "title_rule": "$check",
        "description": "ulimit -n: '${count}', too low, should be greater than '${threshhold}'"
    }
]'

这个脚本挺有用,我之前就被这个问题难倒过,很有印象:) “Too Many Open Files” Error on Linux,网上有很多类似方案可以参考。这里通过这个标本可以自动发现生产环境 Linux 句柄是否够用默认是小于2048就触发报警。

报警事件格式是json,字段含义如下

参数名

类型

说明

event_status

string

事件状态,可选值:Ok、Info、Warning、Critical

labels

object

附加标签,这些标签会附加到这个事件上,不同的事件就是通过 labels 来区分的

title_rule

string

事件标题,支持模板,模板中的变量是 labels 中的字段

description

string

事件描述,可以使用 markdown 格式

利用exec插件,通过写脚本,输出json,可以很方便的自定义一些报警。

  • http 插件

http插件可以用于第三方API接口的存活检查。

more conf.d/p.http/http.toml
[[instances]]
targets = [
    "https://baidu.com",
    "http://a.cn",
]

# # Concurrent requests to make per instance
# concurrency = 10

# # gather interval
# interval = "30s"

# # Optional append labels
# labels = { env="production", team="devops" }

## Set http_proxy (catpaw uses the system wide proxy settings if it's is not set)
# http_proxy = "http://localhost:8888"

## Interface to use when dialing an address
# interface = "eth0"

## HTTP Request Method
# method = "GET"

## Set timeout (default 5 seconds)
# timeout = "5s"

## Whether to follow redirects from the server (defaults to false)
# follow_redirects = false

## Optional HTTP Basic Auth Credentials
# basic_auth_user = "username"
# basic_auth_pass = "pa$$word"

## Optional headers
# headers = ["Header-Key-1", "Header-Value-1", "Header-Key-2", "Header-Value-2"]

## Optional HTTP Request Body
# payload = '''
# {'fake':'data'}
# '''

## Optional TLS Config
# use_tls = false
# tls_ca = "/etc/catpaw/ca.pem"
# tls_cert = "/etc/catpaw/cert.pem"
# tls_key = "/etc/catpaw/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false

[instances.expect]
## Optional expected response status code.
response_status_code = ["20*", "30*"]
## Optional substring match in body of the response (case sensitive)
response_substring = "html"
## Optional alert when cert will expire in x hours
cert_expire_threshold = "72h"

[instances.alerting]
## Enable alerting or not
enabled = true
## Same functionality as Prometheus keyword 'for'
for_duration = 0
## Minimum interval duration between notifications
repeat_interval = "5m"
## Maximum number of notifications
repeat_number = 3
## Whether notify recovery event
recovery_notification = true
## Choice: Critical, Warning, Info
default_severity = "Warning"

可以按需来修改配置,最简单的就是把所有接口地址都填写到 targets 里,就能实现接口探测。

  • journaltail 插件 journaltail 采集插件,可以读取近期系统日志,grep 关键字来进行事件报警。
more conf.d/p.journaltail/journaltail.toml
[[instances]]
# journalctl -S -${time_span}
time_span = "1m"
# relationship: or
filter_include = ["*Out of memory*", "*nf_conntrack: table full, dropping packets*"]
filter_exclude = []
# check rule name
check = "Critical System Errors"
# # gather interval
interval = "30s"

[instances.alerting]
## Enable alerting or not
enabled = true
## Same functionality as Prometheus keyword 'for'
for_duration = 0
## Minimum interval duration between notifications
repeat_interval = "5m"
## Maximum number of notifications
repeat_number = 3
## Whether notify recovery event
recovery_notification = true
## Choice: Critical, Warning, Info
default_severity = "Warning"
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: Controller Manager原理分析 下一篇: LNMP学习
  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  6YY0QMPUXEwu   2023年12月10日   28   0   0 linux网卡
  Ex81gqy3LOX7   2023年12月07日   19   0   0 linux
  nIt0XG0acU8j   2023年12月11日   29   0   0 linuxhtop
  nIt0XG0acU8j   2023年12月09日   33   0   0 linuxsort