Prometheus 教程

AlertManager 配置介绍

Alertmanager 通过命令行标志和配置文件进行配置。命令行标志用于配置不可更改的系统参数,而配置文件则用于定义抑制规则、通知路由和通知接收器。

Alertmanager 可以在运行时重新加载配置,通过向 AlertManager 进程发送 SIGHUP 或向 /-/reload 接口发送 HTTP POST 请求都会触发配置重载。注意,如果新的配置文件存在语法错误,将不会加载配置文件,新的修改将无效,并记录错误。

如果使用 可视化编辑器 来建立路由树,就可以避免很多错误,编辑器界面如下图:

AlertManager 配置介绍

提示:如果要查看 AlertManager 所有可用的命令行标志,请运行 alertmanager -h 命令。


配置文件介绍

要指定加载哪个配置文件,请使用 --config.file 标志,例如:

./alertmanager --config.file=alertmanager.yml

AlertManager 配置文件采用 YAML 格式,并由下面描述的方案进行定义。括号表示参数为可选参数。对于非列表参数,其值将设置为指定的默认值。

通用占位符定义如下:

  • <duration>:与正则表达式 ((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0) 匹配的持续时间,例如 1d、1h30m、5m、10s

  • <labelname>:与正则表达式 [a-zA-Z_][a-zA-Z0-9_]* 匹配的字符串

  • <labelvalue>:一串统一码字符

  • <filepath>:当前工作目录中的有效路径

  • <boolean>:一个布尔值,取值为 true 或 false

  • <string>:常规字符串

  • <secret>:作为秘密的常规字符串,例如密码

  • <tmpl_string>:一个字符串,在使用前经过模板扩展

  • <tmpl_secret>:一个在使用前经过模板扩展的字符串,它是一个秘密字符串

  • <int>:一个整数值

  • <regex>:任何有效的RE2 正则表达式(regex 的两端都有锚点。要取消锚定,请使用 .*<regex>.*)。

文件布局和全局设置

全局配置指定了在所有其他配置上下文中都有效的参数,它们也是其他配置部分的默认值。本页下面将介绍其他顶级配置部分。

global:
  # 默认的 SMTP From 标头字段。
  [ smtp_from: <tmpl_string> ]
  # 用于发送电子邮件的默认 SMTP smarthost,包括端口号。
  # 端口号通常为 25,对于通过 TLS 的 SMTP(有时称为 STARTTLS),则为 587。
  # 例如:smtp.example.org:587
  [ smtp_smarthost: <string> ]
  # 用于标识 SMTP 服务器的默认主机名。
  [ smtp_hello: <string> | default = "localhost" ]
  # 使用 CRAM-MD5、LOGIN 和 PLAIN 进行 SMTP 验证。如果为空,则 Alertmanager 不会验证 SMTP 服务器。
  [ smtp_auth_username: <string> ]
  # SMTP 验证的密码
  [ smtp_auth_password: <secret> ]
  # SMTP 验证的密码,来自文件
  [ smtp_auth_password_file: <string> ]
  # 使用 PLAIN 进行 SMTP 验证
  [ smtp_auth_identity: <string> ]
  # 使用 CRAM-MD5 进行 SMTP 验证
  [ smtp_auth_secret: <secret> ]
  # 默认的 SMTP TLS 要求
  # 请注意,Go 不支持与远程 SMTP 端点的未加密连接
  [ smtp_require_tls: <bool> | default = true ]

  # 用于 Slack 通知的 API URL。
  [ slack_api_url: <secret> ]
  [ slack_api_url_file: <filepath> ]
  [ victorops_api_key: <secret> ]
  [ victorops_api_key_file: <filepath> ]
  [ victorops_api_url: <string> | default = "https://alert.victorops.com/integrations/generic/20131114/alert/" ]
  [ pagerduty_url: <string> | default = "https://events.pagerduty.com/v2/enqueue" ]
  [ opsgenie_api_key: <secret> ]
  [ opsgenie_api_key_file: <filepath> ]
  [ opsgenie_api_url: <string> | default = "https://api.opsgenie.com/" ]
  # 微信相关配置
  [ wechat_api_url: <string> | default = "https://qyapi.weixin.qq.com/cgi-bin/" ]
  [ wechat_api_secret: <secret> ]
  [ wechat_api_corp_id: <string> ]
  [ telegram_api_url: <string> | default = "https://api.telegram.org" ]
  [ webex_api_url: <string> | default = "https://webexapis.com/v1/messages" ]
  # 默认 HTTP 客户端配置
  [ http_config: <http_config> ]

  # 如果警报不包含 EndsAt,则 ResolveTimeout 是警报管理器使用的默认值。
  # 这对来自 Prometheus 的警报没有影响,因为它们总是包含 EndsAt。
  [ resolve_timeout: <duration> | default = 5m ]

# 从中读取自定义通知模板定义的文件
# 最后一个组件可以使用通配符匹配器,例如 'templates/*.tmpl'
templates:
  [ - <filepath> ... ]

# 路由树的根节点
route: <route>

# 通知接收器列表
receivers:
  - <receiver> ...

# 抑制规则列表
inhibit_rules:
  [ - <inhibit_rule> ... ]

# 已摒弃:使用下面的 time_intervals
# 静音路由的静音时间间隔列表
mute_time_intervals:
  [ - <mute_time_interval> ... ]

# 静音/激活路由的时间间隔列表,见路由配置章节
time_intervals:
  [ - <time_interval> ... ]
说说我的看法
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号